I'm using awk '{print $1}' and it works most of the time to print the contents of a mysql query loop, but occationally I get a field with some special character in it, is there a way to tell awk to ignore all special characters between my FS? I have >186K records, so building a list of ALL special characters might be tough, though I've only noticed ' and ) so far. the FS is a , .
a sample 'special' record (or 2) would help.
also a desired output, please.
input:
San Jose, 5101, US
Hawk's Crossing, 3421, NZ
Westfork), vn322, RU
output:
loop1
a=San Jose
b=5101
c=US
loop2
a=Hawk's Crossing
b=3421
c=NZ
loop3
a=Westfork)
b=Vn322
c=RU
nawk '
BEGIN {
FS=","
split("a,b,c,d,e", a, FS)
}
{
for(i=1;i<=NF;i++)
printf("%s%s%s", (i==1)?"loop"++loop ORS:"", a"="$i, (i==NF)?ORS ORS:ORS)
}' inputFile
Is it possible to explain a little of what's happening in your script, I'm trying to extend my awk knowledge a little bit? I could hack it and make it work, but I want to understand it.
Or:
awk -F", " '{print "loop" ++i RS "a=" $1 RS "b=" $2 RS "c=" $3 RS}' file
well, it's not awk,
but in perl you can,
$ perl -ne 'chomp;print "\Q$_\E\n"' file
which escapes all but [A-Z][a-z_]