Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AIX 5.3: need help removing zeroes using sed or any other method 1

Status
Not open for further replies.

dstxaix

Programmer
Dec 22, 2005
78
US
Hi

I have a @ delimited file containing lines like
Code:
@00{@00{@00000{@
@0{@000{@
I would like to strip off the zeroes if they are the only values between two @ symbols or if the 2 delimiters have a few zeroes and a "{" character.

I tried below code and it seems to do this only for alernate elements.
Code:
sed 's/@[0]*{@/@{@/g' inputfile.txt

Any help is appreciated
 
The reason it behaves like that is because it only processes each line once. The first part matches the red component, @00{@00{@00000{@, performs the replacement, @{@00{@00000{@, and then starts working on the rest of the string, @{@00{@00000{@. However the blue part no longer matches your search string, so it is not replaced, and the purple part is the next match that sed finds and replaces.

One simple workaround is to to the replacement twice:

Code:
sed 's/@00*{@/@{@/g;s/@00*{@/@{@/g' inputfile.txt

Notice I used 00* to mean one-or-more zeros, otherwise the second replacement would just match the first @{@ and do nothing.

Annihilannic.
 
Anni

This is perfect.

It works for me.

Have a STAR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top