1752782 Members
6324 Online
108789 Solutions
New Discussion юеВ

usage of sed

 
Ralf Buchhold
Regular Advisor

usage of sed

Hello
can I insert a text before each linefeed
in a textfile ?
Which is the correct command ?
Thanks
Ralf
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: usage of sed

Ralf,

I think something like this should do it:

sed 's/$/your_text$/'

You may have to experiment a bit with it.


Pete

Pete
Muthukumar_5
Honored Contributor

Re: usage of sed

We can use sed / awk / command line script too for this.

sed:

sed "s/$//"

awk:

awk '{ print $0"" }'

perl:

perl -pe 's/$//'

commandline:

while read line; do

echo $line

done < inputfile > outputfile

HTH.
Easy to suggest when don't know about the problem!
harry d brown jr
Honored Contributor

Re: usage of sed

Pete,

Shame on you!

DO NOT PUT THE last $ in your sed string

sed 's/$/your_text/'

otherwise a $ will be in your output (ouch)

Pete, go have some more coffee :-))))))))


live free or die
harry
Live Free or Die
Pete Randall
Outstanding Contributor

Re: usage of sed

Thanks, Harry - coffeeing now.

Pete
Bharat Katkar
Honored Contributor

Re: usage of sed

Hi Ralf,
Go thr' this link:
http://www.hk8.org/old_web/unix/sedawk/index.htm
That should help u experiment. :)
Regards,
You need to know a lot to actually know how little you know
Geoff Wild
Honored Contributor

Re: usage of sed

Here's a handy page - Sed One liners:

http://www.unixguide.net/unix/sedoneliner.shtml

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.