Home > Archive > AWK > August 2007 > Make awk recognizes lists as sh
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Make awk recognizes lists as sh
|
|
| Silas Silva 2007-08-23, 6:57 pm |
| 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!
| |
| Vassilis 2007-08-23, 6:57 pm |
| On 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
|
|
|
|
|