Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Help parsing a file from one regex to another
- X-seq: zsh-users 9061
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Help parsing a file from one regex to another
- Date: Fri, 08 Jul 2005 17:16:27 +0000
- In-reply-to: <20050708073037.GB9744@xxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <e3b7bac05070723366cd51ebf@xxxxxxxxxxxxxx> <20050708073037.GB9744@xxxxxxxxxxxxxxxxxxxxx>
On Jul 8, 5:30pm, Doug Kearns wrote:
} Subject: Re: Help parsing a file from one regex to another
}
} > I am trying to parse a range of data out of a file from one regular
} > expression up to another. The input starts with `^@main::FLAGS' and
} > goes up to the next `)' I am using awk right now, but it is *ugly*
}
} flags=( ${=${${${(f)"$(<$tmp_file)"}[(r)@main::FLAGS*,(r)\);]}#*\"}//[^[:upper:][:blank:]]/} )
That only works if the closing paren is on a line by itself, I think.
You need (r)*\); in the subscript expression, maybe even (r)*\);* if there
may be other stuff following the close-paren.
Also, that expression won't work if you replace FLAGS with PRIORITIES,
because (r)*\); always matches the end of the FLAGS assignment, which is
before the beginning of the PRIORITIES assignment.
To extract just the line(s) of interest from the file with sed:
sed -n -e '/^@main::FLAGS.*)/{p;q;}' -e '/^@main::FLAGS/,/)/p'
If you know that the close paren is never on the same line as the @main
then you can eliminate the first -e expression.
So to put the whole thing together:
flags=( ${${$(sed -n -e '/^@main::FLAGS.*)/{p;q;}' -e '/^@main::FLAGS/,/)/p' <$tmp_file)}//[^[:upper:]]/} )
shift flags # Throw away the word "FLAGS" from @main::FLAGS
Messages sorted by:
Reverse Date,
Date,
Thread,
Author