{ record = record $0
# If number of quotes is odd, continue reading record.
if ( gsub( /"/, "&", record ) % 2 )
{ record = record " "
next
}
}
{ print record
record = ""
}
Thanks a lot for all your inputs. The below code soles the problem with the example I had given. When the data had double quotes...
{ record = record $0
# If number of quotes is odd, continue reading record.
if ( gsub( /"/, "&", record ) % 2 )
{ record = record " "
next
}
}
{ print record
record = ""
}
The tr \\n " " removes all the new lines and forms a one big record. I don't want this to happen.
We know that the record is incomplete if the number of quotes it contains isn't even. We use gsub to count the number of quotes in the line:
gsub( /"/, "&" )
replaces each quote with a quote (the & stands for whatever was matched by the regular expression) and returns the number of substitutions made. If that number is odd, i.e., if dividing by 2 gives a non-zero remainder, then the record is incomplete. So we tack on a space and jump back to the top of the input loop.
u didn't mention where you are calling the file in the script
all u said is record?
what do u mean by record !
can u send me the whole script please , i have the similar situation
The above script works fine for some record. I recently got awk error something like more than 199 fields... I'm currently using awk -f {abovescript}.awk on HP-UX 11.0 box...