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.