Talk About Network

Google


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: match nth f...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 6 Topic 2120 of 2347
Post > Topic >>

Re: match nth field and print the whole result

by aclhkaclhk <access_you@[EMAIL PROTECTED] > Jan 4, 2008 at 08:31 PM

On Jan 4, 8:15 pm, Janis Papanagnou <Janis_Papanag...@[EMAIL PROTECTED]
>
wrote:
> aclhkaclhk wrote:
> > We have a number of files:
>
> > 1~peter~hello.txt
> > 2~tom~bye.txt
> > 3~ken~love.txt
> > 4~tom~good.txt
>
> > we would like to search for 2nd field containing "tom" and print the
> > whole filenames.
> > 2~tom~bye.txt
> > 4~tom~good.txt
>
> > we would search something like this:
> > eg. ls . | awk -F"~" '{print $0}'
>
> > pls advise what awk construct could give my output.
>
> 2nd field containing "tom"...
>
>    awk -F"~" '$2~/tom/{print $0}'
>
> or just
>
>    awk -F"~" '$2~/tom/'
>
> and 2nd field _is_ "tom"...
>
>    awk -F"~" '$2=="tom"'
>
> Janis

Thanks all for your kind advise

this one is most suitable for me:
awk -F"~" '$2=="tom"'

I have tested it but this is an exact match. How to match nth field
containing "tom"?

eg.
1~peter~hello.txt
2~tom123~bye.txt
3~ken~love.txt
4~tom456~good.txt

something like: awk -F"~" '$2=="*tom*"' returns
2~tom123~bye.txt
4~tom456~good.txt

Pls advise.
 




 6 Posts in Topic:
match nth field and print the whole result
aclhkaclhk <access_you  2008-01-04 02:39:24 
Re: match nth field and print the whole result
Janis Papanagnou <Jani  2008-01-04 13:15:31 
Re: match nth field and print the whole result
pop <p_o_p@[EMAIL PROT  2008-01-04 14:37:34 
Re: match nth field and print the whole result
Ed Morton <morton@[EMA  2008-01-04 15:01:00 
Re: match nth field and print the whole result
aclhkaclhk <access_you  2008-01-04 20:31:42 
Re: match nth field and print the whole result
Janis Papanagnou <Jani  2008-01-05 05:36:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sun Sep 7 8:28:36 CDT 2008.