Friday 15 April 2011

linux - How do I concatenate two files and write the result back to one of the original files -



linux - How do I concatenate two files and write the result back to one of the original files -

i trying first 4 lines somefile, concatenate them contents of someotherfile , output somefile.

head -4 /somefile | cat - /someotherfile > /somefile

when contents of someotherfile ends in somefile, not first 4 lines. if output totally different file works great.

obviously there issue trying write same file reading from. simplest way accomplish task?

i attempting on redhat enterprise 6, bash shell.

you can save head output temporary variable, this:

head="$(head -4 file)" (echo "$head"; cat someotherfile) >some file

or can remove lines starting 5th , append content of file end:

sed -i '5,$d' somefile cat someotherfile >>somefile

linux bash pipe cat head

No comments:

Post a Comment