Remove command

 
ivy1234
Frequent Advisor

Remove command

I have a large file , the file have many lines , the content is as below , each line MAY be begins or ended with # sign .

#abc
#uid#
yti
#des
#fus
eue#
fds

Can advise if I want to check each line , if it begins or ends with # sign then remove this # sign , if not # , then do nothing ( also , if the # sign is in the middle of the line , then do nothing ) , only remove it if it is begin or end character , can advise what can i do ?

the file above should be changed to

abc
uid
yti
des
fus
eue
fds
6 REPLIES 6
Hemmetter
Esteemed Contributor

Re: Remove command

Hi

you want to replace either linestart "^" followed by hash mark or hashmark followed by
line-end "$" with "nothing" .

That is by "sed":
# sed "s/^#// ; s/#$//" file > newfile

or by "perl":

#
perl -i -pe "s/^#// ; s/#$//" file

here replace the file "inplace" (-i)

see regexp(5), sed(1), perl(1)

rgds
HGH
ivy1234
Frequent Advisor

Re: Remove command

Thx , it works,

if it is not # sign , do the same thing for " sign , how to do it ? thx
Hemmetter
Esteemed Contributor

Re: Remove command

hi again,


it is as easy as either:
# sed 's/^"// ; s/"$//' f
or mask the special char " by \"
# sed 's/^"// ; s/"$//' f


rgds
HGH

ivy1234
Frequent Advisor

Re: Remove command

it works , thanks much for help
Hemmetter
Esteemed Contributor

Re: Remove command

Hi,

You have assigned points to 6 of 93 responses.

If answers you got were helful, you may want donate some points, they cost you nothing.

http://h30499.www3.hp.com/t5/help/faqpage/faq-category-id/kudos#kudos


rgds
HGH

V. Nyga
Honored Contributor

Re: Remove command

Hi HGH,

maybe you can visit this thread?
http://h30499.www3.hp.com/t5/General/Congrats-to-a-new-wiz-Hemmetter/m-p/4606244#M144980


:-)
V.

*** Say 'Thanks' with Kudos ***