Adding text to places in a file
Hello,
I have a script that what i want to do is be able to insert a new line in a text file at a specific place where some other text is found, this other text could be at any place in the file so i do: Code:
grep -n TEXT filename eg: line number 40:stuff written here i want to create new line and enter stuff here 41:stuff written here Hope this makes sense Cheers Regards Mark |
no problems i've worked it out, using sed at last
its like this Code:
sed -e '/text string in file/a\create new line enter this text' FILENAME.BLAH hope its helpful for others |
Look at the "append" (a) command in SED. For example:
cat filename | sed '/^40/a text for the new line' for every line beginning with "40", add a new line following: "text for the new line" |
Quote:
|
"Useless Use Of Cat" UUOC--I am really really sorry. I hope the penalties are not too severe...
"\" not required unless you want to enter your new line text on a new line!! I don't do non-GNU......Hmmm, has a sort of poetic sound to it. With some bad grammar, it might sound even better: I don' do no non GNU.....;) |
Quote:
Quote:
Quote:
|
Thanks, but i had already sorted it and posted my fix which is the same as what you guy's put, but never mind thanks anyway
Regards |
All times are GMT -5. The time now is 07:15 AM. |