betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

14 February 2005

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
    echo $filename
    sed -e "s/^.*view full-size image.*/\ /" \
        $filename  > test.html
    mv test.html $filename
exit 0

No security net given (but I did not expect one from myself).

Posted by betabug at 12:17 | Comments (2) | Trackbacks (0)
ch athens
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
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Tagi-Newsletter | Main | Kein Schnee >>
Re: sed file list loop reminder

Also note that any permission settings are lost due to the copying over of the files. Use chmod afterwards or fix the script :-).

Posted by: betabug at April 20,2005 12:16
Re: sed file list loop reminder

cat test.html > $filename

and then
rm test.html
at the end of the script is the proper way to keep permissions. That replaces the contents, but not the file.

Posted by: betabug at June 22,2006 12:03
Re: sed file list loop reminder

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.

Posted by: betabug at May 20,2010 11:32
You can trackback to:
There are no trackbacks.