Code Comments
Programming Forum and web based access to our favorite programming groups.Hello all!
I have a file with lists in the following form:
"one item" "this is 'another' item" "yet \"another\" item"
It is a well-known format that shell and other languages (Tcl, for
example)
can easily parse. Parsing this line looks like a CSV problem, doesn't
it?
I can easily split fields using '"' as a field separator. But I got
the problem
that '\"' will not escape. To allow parsing of only non-escaped
quotes, I used
the following command:
awk -F '[^\\\\]"' '{ print $1 }' foo
It behaves more or less like expected, but it take out the last letter
of the
string (of course) and it does not take out the first quote of the
line.
Should I have to make a big program intead of a simple field separator
and a
few lines of code to make it work? I thought about replacing every '"'
that is
not "preced"(?) by a backslash '' in by two double quotes '""'. And
them,
using it as a field separator.
What do you think?
Thank you very much!
Post Follow-up to this messageOn 23 , 23:09, Silas Silva <sila...@gmail.com> wrote:
> Hello all!
>
> I have a file with lists in the following form:
>
> "one item" "this is 'another' item" "yet \"another\" item"
>
> It is a well-known format that shell and other languages (Tcl, for
> example)
> can easily parse. Parsing this line looks like a CSV problem, doesn't
> it?
>
> I can easily split fields using '"' as a field separator. But I got
> the problem
> that '\"' will not escape. To allow parsing of only non-escaped
> quotes, I used
> the following command:
>
> awk -F '[^\\\\]"' '{ print $1 }' foo
>
> It behaves more or less like expected, but it take out the last letter
> of the
> string (of course) and it does not take out the first quote of the
> line.
>
> Should I have to make a big program intead of a simple field separator
> and a
> few lines of code to make it work? I thought about replacing every '"'
> that is
> not "preced"(?) by a backslash '' in by two double quotes '""'. And
> them,
> using it as a field separator.
>
> What do you think?
>
> Thank you very much!
Try out
awk -F '" "' '{ $0 = substr($0, 2, length($0) - 2) } rest-script'
files.
Vassilis
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.