Results 1 to 4 of 4
I want to create a script wherein it will put a string somewhere on the text file. But my priority was on top but I hope I can place it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 07-29-2010 #1Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
put string on top of the text
I want to create a script wherein it will put a string somewhere on the text file. But my priority was on top but I hope I can place it in any lines if possible. I tried to create a script using redirect ">" and then put it on top of the file.
The text contains:
I want to put "MY TEXT" so I did the script below:foo
fee
fii
fuu
Is there other way I could do this?Code:#!/bin/bash cat /root/tmp/text > /root/tmp/text.tmp echo "MY TEXT" > /root/tmp/text cat /root/tmp/text.tmp >> /root/tmp/text rm -f /root/tmp/text.tmp
- 07-29-2010 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 468
using "tac" you could save one line:
#!/bin/bash
echo "MY TEXT" >> /root/tmp/text
tac /root/tmp/text > /root/tmp/text.tmp
mv /root/tmp/text.tmp /root/tmp/textthe sun is new every day (heraclitus)
- 07-29-2010 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
put on top
put at line number 10Code:sed '1 i text' file
Code:sed '10 i text' file
- 07-29-2010 #4
this may work too:
Code:sed '1i\ your text goes here' file_name > file_name


Reply With Quote
