Sep 16, 2005 #1 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 ...
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 ...
Sep 16, 2005 #2 TrojanWarBlade Programmer Apr 13, 2005 1,783 GB rename original file, echo text to original file, cat renamed as append onto original file. Trojan. Upvote 0 Downvote
Sep 16, 2005 1 #3 PHV MIS Nov 8, 2002 53,708 FR 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 Upvote 0 Downvote
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
Sep 16, 2005 Thread starter #4 keak Programmer Sep 12, 2005 247 CA Thansk, that did the trick ... !! ahh gotta get used to these stuff from now Upvote 0 Downvote
Sep 17, 2005 #5 feherke Programmer Aug 5, 2002 9,541 RO Hi And PHV's last example with [tt]sed[/tt] : Code: sed -i '1ibeginning text' test.txt Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote
Hi And PHV's last example with [tt]sed[/tt] : Code: sed -i '1ibeginning text' test.txt Feherke. http://rootshell.be/~feherke/