Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append to file 1

Status
Not open for further replies.

smicro

MIS
Dec 26, 2002
281
US
Does anyone know if there is a way to insert text in a file before the current text that is in there(not append).
So for example if I have file1 and want to get the first 3 lines of that file and insert those 3 lines into the beginning of file2. I have sed 3q file1 to grab the 3 lines from file1 but can't figure out how to get that output into the first 3 lines of file2. I didn't want to append to the file because the three lines from file1 need to go before the existing lines in file2. Looked at the head command but not exactly sure if I can incorporate that. Thanks.
 
What about this:

head -3 file1 > tmpfile
cat file2 >> tmpfile
mv tmpfile file2
 
Thanks hoinz, I was thinking something like this but wasn't sure if there was a way to doit without creating a tmp file. But thanks for the suggestion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top