Re: help--with sed (148 Views)
Reply
Frequent Advisor
Karthik_sg
Posts: 68
Registered: ‎04-18-2007
Message 1 of 5 (148 Views)

help--with sed

Hi all,
I have a file called fields.txt and i have the following in it as contents
`cat /ghl`
echo "debug"
echo "complete"
My question is how do i insert some text in the first line before `cat /ghl` using sed.
And how do i insert after last word in the last line using sed.Please help me guys its urgent...
Please give the code..thanks in advance..
Honored Contributor
Ivan Ferreira
Posts: 6,957
Registered: ‎05-07-2004
Message 2 of 5 (148 Views)

Re: help--with sed

If you run this:

sed "1 s/^/word_to_insert /" filename

You will add "word_to_insert " to the begining of the first line in "filename".
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Honored Contributor
Ivan Ferreira
Posts: 6,957
Registered: ‎05-07-2004
Message 3 of 5 (148 Views)

Re: help--with sed

BTW karthik, I see in your profile "I have assigned points to 5 of 66 responses to my questions."

Please keep asigning points. For help about this, see:

http://forums1.itrc.hp.com/service/forums/helptips.do?#28
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 5 (148 Views)

Re: help--with sed

Hi:

# sed -e '1 s/^/_BEGIN_/' -e '$ s/$/_END_/' fields.txt

...using your example, this would yield:

_BEGIN_`cat /ghl`
echo "debug"
echo "complete"_END_

Regards!

...JRF...

Occasional Visitor
H R Dileepkumar
Posts: 4
Registered: ‎01-23-2008
Message 5 of 5 (148 Views)

Re: help--with sed

hi friend,

to insert some text first line before. use this command line

sed "1 s/^/word_to_insert /" filename

to insert some text lost line before. use this command line

sed "(lost line number) s/$/word_to_insert /" filename
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.