Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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
Occasional Visitor

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