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!

appending text to the top of a file 1

Status
Not open for further replies.

keak

Programmer
Sep 12, 2005
247
CA
Hi,
If we want to append a text to a file at the bottom we can use the command
echo "bottom text" >> test.txt

is there a way to append a string to the beginning of a textfile with a similar method?

I have been googling for a while with no luck ...
 
rename original file, echo text to original file, cat renamed as append onto original file.


Trojan.
 
One way:
(echo "beginning text"; cat test.txt) > test.$$ && mv test.$$ test.txt
Another way:
awk 'BEGIN{print "beginning text"}1' test.txt > test.$$ && mv test.$$ test.txt

Without temp file:
echo "1i\nbeginning text\n.\nw\nq" | ed -s test.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thansk, that did the trick ... !!
ahh gotta get used to these stuff from now
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top