1753637 Members
5879 Online
108798 Solutions
New Discussion юеВ

help--with sed

 
Karthik_sg
Frequent Advisor

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..
4 REPLIES 4
Ivan Ferreira
Honored Contributor

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?
Ivan Ferreira
Honored Contributor

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?
James R. Ferguson
Acclaimed Contributor

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...

H R Dileepkumar
New Member

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