Quote:
> I need to parse a record, where a empty record
> looks like this:
> "" "" ""
> But the problem I'm having is there can be quotes inside the quotes,
> like this:
> "IC1" ""D" Flip-Flop" "74HC74"
> "IC2" " "D" Flip-Flop " "4013"
> How do I break that in to the three fields?
Oh oh, rather broken design (but that's not yourfault, of course).
If the first and third column never have whitespace, you could try
extracting these columns first, and leave the second column for further
treatment:
FS = " "
Field[1] = $1
Field[3] = $NF # the last field
$1 = $NF = ""
Field[2] = $0
# now discard leading and trailing blanks and doublequotes:
for(i in Field)
{
gsub(/^[\" ]+/,"",Field[i])
gsub(/[\" ]+$/,"",Field[i])
Quote:
}
If the first and the third column might have embedded whitespace, but
never embedded doublequotes, I would try:
FS = "\""
Field[1] = $2 # $1 is before the first doublequote now
Field[3] = $(NF-1)
$2 = $(NF-1) = ""
# and now again:
Field[2] = $0
# now discard leading and trailing blanks and doublequotes:
for(i in Field)
{
gsub(/^[\" ]+/,"",Field[i])
gsub(/[\" ]+$/,"",Field[i])
Quote:
}
Regards...
Michael