Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Make awk recognizes lists as sh
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!


Report this thread to moderator Post Follow-up to this message
Old Post
Silas Silva
08-23-07 11:57 PM


Re: Make awk recognizes lists as sh
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


Report this thread to moderator Post Follow-up to this message
Old Post
Vassilis
08-23-07 11:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:40 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.