Re: awk question
Re: awk question
- Subject: Re: awk question
- From: Cameron Hayne <email@hidden>
- Date: Fri, 1 Dec 2006 14:30:19 -0500
On 1-Dec-06, at 1:08 PM, John C. Welch wrote:
each line has two field delimiters. The most common one is a space.
that's easy. The problem is in what I want to be column two,
there’s a text string surrounded by double quotes that contains
spaces. As an example:
17 "Security Update for Exchange 2000 Server (KB894549)"
zeroDotZero application 2005-10-7,13:45:34.0
so I’m trying to get awk to run as “your field delimiters are
spaces OR double quotes with any number of any characters or
whitespace followed by double quotes”
I can get close, but not close enough to what I want which would be:
$1 = 17
$2 = "Security Update for Exchange 2000 Server (KB894549)"
$3 = zeroDotZero
$4 = application
$5 = 2005-10-7,13:45:34.0
You could do this with Perl - for example:
perl -ne '@values = /^\s*(\S+)\s+("[^"]*")\s+(\S+)\s+(\S+)\s+(\S+)\s*
$/; print join("\n", @values),"\n"'
Explanation of the regex:
/^\s* start of line followed by optional space
(\S+) non-space chars, captured into $values[0]
\s+ some space
("[^"]*") a quote, some (possibly zero) number of non-quote
chars, then a quote, captured into $array[1]
\s+ some space
(\S+) non-space chars, captured into $values[2]
\s+ some space
(\S+) non-space chars, captured into $values[3]
\s+ some space
(\S+) non-space chars, captured into $values[4]
\s*$/ optional space at end of line
--
Cameron Hayne
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden
References: | |
| >awk question (From: "John C. Welch" <email@hidden>) |