1753786 Members
7442 Online
108799 Solutions
New Discussion юеВ

One Liner sed

 
Sagar Sirdesai
Trusted Contributor

One Liner sed

Hi
I've sed file which writes # at the start and ! at the end

s/^/#/
s/$/!/

This works fine.
But advise me how can convert this in to a sed oneliner instead of using the se file

Sagar
2 REPLIES 2
Hein van den Heuvel
Honored Contributor

Re: One Liner sed

Well,... just put all edits on the command line, using -e to introduce each.
And if you had picked a character other then '!' if could be:

# sed -e s/^/#/ -e s/$/~/ tmp.tmp

The issue is that depending on the shell (I think) you will need to escape or otherwise hide the "!"

So try:

# sed -e s/^/#/ -e s/$/\!/ your-file

or


# sed -e s/^/#/ -e 's/$/!/' your-file

fwiw,
Hein
Dennis Handly
Acclaimed Contributor

Re: One Liner sed

>HeinThe issue is that depending on the shell (I think) you will need to escape or otherwise hide the "!"

Real shells don't treat "!" as special.

And it's probably a good idea to always use '' for sed expressions:
sed -e 's/^/#/' -e 's/$/!/' your-file