sed file list loop reminder
Edit a list of files with sed, ...again
Just so I won't have to diggle this out agai and again, here is a reminder to myself :-) Making a small edit with sed on a list of files in a directory can be done like this:
for filename in detail-??.html detail-???.html
sed -e "s/^.*view full-size image.*/\ /" \
$filename > test.html
mv test.html $filename
No security net given (but I did not expect one from myself).
Life in Athens (Greece) for a foreigner from the other side of the mountains.
And with an interest in digital life and the feeling of change in a big city.
Multilingual English - German - Greek.
Main blog page
Some of the most sought after posts, judging from access logs and search engine queries.
Apple & Macintosh:
Security & Privacy:
Athens for tourists and visitors:
Life in general:
Also note that any permission settings are lost due to the copying over of the files. Use chmod afterwards or fix the script :-).
cat test.html > $filename
at the end of the script is the proper way to keep permissions. That replaces the contents, but not the file.
There is an even simpler solution, assuming your sed is new enough to have the -i command line switch:
sed -i .sedbak 's/search_for/replace_with/g' *.cs
Where -i will instruct sed to make the change "in-place", while keeping a backup file with the extension given.
You can trackback to: http://betabug.ch/blogs/ch-athens/42/tbping
There are no trackbacks.