Re: Is that problem for awk?



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

.



Relevant Pages