Eric Blake wrote: > Brock Noland wrote: > | I find myself for whatever reason, wanting to prepend a file (or > | stdin) to a file. Most often when dealing XML that does not have a top > | level tag. > | > | This can be done safely in the shell but requires a lot of work. > | (Maybe there is already a better way?) > > What shell commands have you been trying? I find the following to be > relatively simple to do: > > { echo header; cat file; } > file1 && mv file1 file
In addition to the above if I restrict myself to programs that already know how to edit files in place I can think of a few additional easy ways. Sed of course comes to mind. Here is one way to use sed to edit a file in place and insert "foo" at the first line of the file. sed --in-place '1i\ foo' bar Using perl: perl -i -lpe 'print "foo" if $. == 1;' bar Using ruby: ruby -i -lpe 'print "foo" if $. == 1' bar Being an 'ed' fan I would would probably use ed. ed -s bar <<EOF i foo . w q EOF Or to read a file "foofile" at the first line of the file. ed -s bar <<EOF 0r foofile w q EOF Bob _______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils