Buckaroo Buddha has asked for the wisdom of the Perl Monks concerning the following question:
|value 1|value two|"|Value 3 was "NULL"|2001/06/06|
unfortunately, in this case SAS can't handle quotes very well. So I must clean the file before SAS gets its ruddy little paws on it.
I had hoped to do a quick and sexy inline thing to the effect of:
perl -pi.bak -e "s/\|\"\|/\|\|/g" filename
open OUTFILE, ">>@ARGV[0].dat"; while (<>) { $_ =~ s/\|\"\|/\|\|/g; print OUTFILE $_; } close OUTFILE;
sweet, it works! no problem
but now i've found that unmatched quotes still happen at other places in the data. I must instead come up with a way of saying:
"if you find a | before you find a second quote you must substitute it for a blank space"
now one way would be to:
the two questions i have are:while (<>) { split /\|/; my $output = "|"; foreach my $value (@_) { if ($value =~ m/"{1}/) { $value =~ s/"//g; } $output =. $value . "|"; } print $output; }
2) is there a way to match any ODD number of quotes as opposed to just one quote?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Delete unmatched quotes from a delimited file?
by bwana147 (Pilgrim) on Jul 24, 2001 at 20:02 UTC | |
|
Re: Delete unmatched quotes from a delimited file?
by wine (Scribe) on Jul 24, 2001 at 20:27 UTC | |
|
(tye)Re: Delete unmatched quotes from a delimited file?
by tye (Sage) on Jul 25, 2001 at 01:30 UTC | |
|
negative lookahead to the rescue! (boo)
by boo_radley (Parson) on Jul 24, 2001 at 20:47 UTC | |
|
(MeowChow) Re: Delete unmatched quotes from a delimited file?
by MeowChow (Vicar) on Jul 24, 2001 at 21:58 UTC |