Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Is that pro...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 16 of 16 Topic 2155 of 2241
Post > Topic >>

Re: Is that problem for awk?

by Andrew Schorr <aschorr@[EMAIL PROTECTED] > Feb 9, 2008 at 10:55 AM

On Feb 7, 3:37 pm, Kurda Yon <kurda...@[EMAIL PROTECTED]
> 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




 16 Posts in Topic:
Is that problem for awk?
Kurda Yon <kurdayon@[E  2008-02-07 12:37:10 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-07 14:45:08 
Re: Is that problem for awk?
"Luuk" <luuk  2008-02-08 13:50:57 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-08 08:58:17 
Re: Is that problem for awk?
Luuk <Luuk@[EMAIL PROT  2008-02-08 16:19:40 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-08 10:19:07 
Re: Is that problem for awk?
gazelle@[EMAIL PROTECTED]  2008-02-08 16:48:13 
Re: Is that problem for awk?
Janis Papanagnou <Jani  2008-02-08 18:11:32 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-08 11:29:42 
Re: Is that problem for awk?
Janis Papanagnou <Jani  2008-02-08 19:11:04 
Re: Is that problem for awk?
"Luuk" <luuk  2008-02-08 10:05:11 
Re: Is that problem for awk?
William James <w_a_x_m  2008-02-09 01:00:53 
Re: Is that problem for awk?
Luuk <Luuk@[EMAIL PROT  2008-02-09 10:34:28 
Re: Is that problem for awk?
gazelle@[EMAIL PROTECTED]  2008-02-09 13:09:48 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-09 09:49:35 
Re: Is that problem for awk?
Andrew Schorr <aschorr  2008-02-09 10:55:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 4:24:24 CDT 2008.