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!

Insert text into text using korn shell script

Status
Not open for further replies.

sambam

Programmer
Feb 5, 2008
3
MA
Hi everybody,
I have a file witch i want to edit. I want to insert new line just before a constante :):). Here is the content of the file :
------------------
tttt
tttt

::
ffff
fffff
---------------------

Here is the result i want using script shell ksh

------------------
tttt
tttt

new line test test
::
ffff
fffff
---------------------

Thanks for help :)
 
Try
Code:
awk '/::/ {print "Text to be inserted"} {print}' /path/to/file
Tested on RedHat ES4

On the internet no one knows you're a dog

Columb Healy
 
Thanks, cool it work.
But i have a question, can i save my modifications in the same file without re-direction?
 
I have another question please, if i want to insert 2 line or plus? how can i do it?

result :
------------------
tttt
tttt

new line1 test test
new line2 test test
new line3 test test
::
ffff
fffff
---------------------
 
I believe that you can do the modification in place using 'ed' but I don't know how to do it. As for the multiple line bit, something along the lines of
Code:
awk '/::/ {printf "line one\nline two\nline three\n"} {print}' /path/to/file

On the internet no one knows you're a dog

Columb Healy
 
Perl does in-file editing but I don't know much about it... here is something to start you off with though.

perl -i-p -e "s/search_str/replacement_str/g" file

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top