[prog] using sed on multiple files

Dan dan at cellectivity.com
Sat Jul 9 02:38:50 EST 2005


> But I need it to permanently make the change not just spit the output 
> to STDOUT

Try using sed's cousin ed, a very primitive file editor. ed takes
keyboard commands similar to those preceded by a ":" in vi, and its
input can be piped.

For example:

ed foo.txt <<EOF
1,\$s/foo/bar/g
wq
EOF

Note: you would normally write 1,$s/foo/bar/g (which means: execute the
substitution on each line from line 1 to the end ($)). However, you need
the backslash to avoid the shell expanding the "$s".

-- 
  If children were meant to be seen and not heard, they would have
  been made huge in size and tiny in voice, instead of the other
  way around.




More information about the Programming mailing list