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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace characters within a field

Status
Not open for further replies.

ebuilder

ISP
Jan 20, 2001
2
US
Hi,
I was given a pipe delimited file that has some extra pipes in it. I need to remove them. I delimited the problem area with ~'s So I need to remove all |'s within that field.
Any help would be appreciated.
Thanks,
Eric
 
ebuilder, you can do this with sed. If you want to remove all pipes between the ~'s, and also remove the ~'s then the command is

sed 's/~[|]*~//g' inputfile > outputfile

If you want retain the ~'s, then it's

sed 's/~[|]*~/~~/g' inputfile > outputfile

Greg.
 
Hi Greg,
That makes sense, in fact sed was my first choice, however I was told that it couldn't be done.
I tried that command and have been able to get sed to remove the ~'s but not the pipes between them. I'm using RH 6.2. This field is an HTML field and has |'s scattered throughout like this:
</B> ALL EXC COMET|COUGAR|FAIRLANE|MUSTANG<BR>
any ideas?

another method I have been working on is:

cat prod.dat | awk 'BEGIN { FS = &quot;~&quot; };{$1 = gsub(/\|/,eric)};{print $1 }' >> new.dat
but I clearly have something wrong in the part where I use the gsub function, the = I think...
thanks,
Eric
 
ebuilder-

Here is a short nawk program to remove more than 1
extra pipe.

nawk '/\174/ {gsub(/\174+/,&quot;|&quot;);print}' yourfile > outfile

Removes all but one pipe wherever found in records.

Hope this helps.



flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top