Re: Is that problem for awk?
- From: Andrew Schorr <aschorr@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 9 Feb 2008 10:55:04 -0800 (PST)
On Feb 7, 3:37 pm, Kurda Yon <kurda...@xxxxxxxxx> wrote:
I have the following problem. In my text-file each line has the
following format:
field_1 field_2 ... field_n (tf. field_1a, field_2a ... field_ka)
And I need to extract field_1a, field_2a, ...and field_ka.
Just for variety, here's a solution that involves using a regular
expression
to grab the part of the input that you do want (as opposed to the
other solutions
which focus on discarding the part of the input that you don't want):
bash-3.1$ cat /tmp/file
field_1 field_2 ... field_n (tf. field_1a, field_2a ... field_ka)
bash-3.1$ gawk 'match($0,/\(tf\. (.*)\)$/,f) {print f[1]}' /tmp/file
field_1a, field_2a ... field_ka
Granted this involves using a gawk extension (the 3rd array argument
to
match), but this is a very powerful feature that can help in many
situations.
Regards,
Andy
.
- References:
- Is that problem for awk?
- From: Kurda Yon
- Is that problem for awk?
- Prev by Date: [announcement] runawk-0.11.0 has been released
- Next by Date: Re: GUI Awk
- Previous by thread: Re: Is that problem for awk?
- Next by thread: [announcement] runawk-0.11.0 has been released
- Index(es):
Relevant Pages
|