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

Any SED or AWK gurus out there? Heres a tough one... 1

Status
Not open for further replies.

sumgirl

IS-IT--Management
Mar 19, 2003
55
US
"1008","Hey, guy",0.00,"PO 44","Reno","NV","89504"

Anyone know how I can strip the quotes and change the comma-delimters to pipes while keeping the embedded comma that is a valid part of the "Hey, guy" string? Also, note the third field which is not a string and has no quotes. I need to do this on an AIX system with SED or maybe AWK so please no perl, c, ect...

Please help. Got this file from a vendor and its driving me nuts!
 
use sed to replace ", with the pipe |
and again to replace " with null
sed 's/",/|/g; s/"//g' yourfile > newfile




Dickie Bird (:)-)))
 
I think this will not change the "," behind "0.00"
into Pipe. :(

bye
Ruediger
 
Rats ! ...... should be :
sed 's/",/|/g; s/,"/|/g; s/"//g' yourfile > newfile





Dickie Bird (:)-)))
 
Cool!
I'm just a beginner to sed, awk and AIX and always surprised how regular expressions solve problems...

Seems that you have earned a star. :))


bye
Ruediger
 
Hey all, a new wrinkle...I almost got it with that second to last post but my files includes two numeric non-quoted fields like so:

*",1.00,2.00,"

as well as a couple of:

*",5.00,"*

This makes it harder huh?
-d
 
Not pretty but works
sed -e 's/, /? /g;s/",/|/g; s/,"/|/g; s/"//g;s/,/ /g;s/?/,/g'

Tony ... aka chgwhat

When in doubt,,, Power out...
 
Sorry this only works as long as the data that contains the comma, has a space after the comma.
simpler version.
sed -e 's/, /? /g; s/"//g; s/,/|/g; s/?/,/'

otherwise you may want something like this
awk -F, '{print $1"|"$2", " $3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$9"|"$10}' |sed -e 's/"//g; s/ / /g'



Tony ... aka chgwhat

When in doubt,,, Power out...
 
This awk-solution should work, too.
Save the following awk-script as "filter.awk":


BEGIN {inside=0;}
END {printf("\n");}
{
for (i=1; i<=length(); i++) {
c=substr($0,i,1);
if (c==&quot;\&quot;&quot;) {
inside=1-inside;
continue;
}
if (c==&quot;,&quot;&&!inside) c=&quot;|&quot;;
printf(c);
}
}


Create the input file &quot;text.csv&quot;:

&quot;1008&quot;,&quot;Hey, guy&quot;,0.00,&quot;PO 44&quot;,&quot;Reno&quot;,&quot;NV&quot;,&quot;89504&quot;


The command:

awk -f filter.awk < text.csv

should give you the wanted result (Thanx to 'cat' for this little script!)

regards
Rudi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top