simple grep/awk
am 12.09.2007 23:23:20 von bhaveshah
Hi Gurus,
I've a file with 1000 lines in format below. I am looking for only col
2 which is teka, deka and meka but if i do awk -F '{print $2}' it
gives me anything after space. How do i look only for the col 2 with
awk? please help.
mide/MC MIDE Sent teka 6009
mide/MC MIDE Templates deka 6009
test/test12 test/test 1 2 meka 6583
Thanks in Advance
shahb
Re: simple grep/awk
am 12.09.2007 23:38:58 von Ed Morton
explor wrote:
> Hi Gurus,
> I've a file with 1000 lines in format below. I am looking for only col
> 2 which is teka, deka and meka but if i do awk -F '{print $2}' it
> gives me anything after space. How do i look only for the col 2 with
> awk? please help.
>
> mide/MC MIDE Sent teka 6009
> mide/MC MIDE Templates deka 6009
> test/test12 test/test 1 2 meka 6583
>
> Thanks in Advance
> shahb
>
Awk works on records (normally lines) split into fields (normally
separated by any contiguous sequences of any white-space). If you want
awk to use something else as the field separator, you need to tell awk
what that separator is. For example:
awk -F'\t' '{print $2}' file
would print the 2nd field in each record where the fields are separated
by a single tab character.
Ed.
Re: simple grep/awk
am 13.09.2007 01:28:46 von bhaveshah
On 12 Sep, 14:38, Ed Morton wrote:
> explor wrote:
> > Hi Gurus,
> > I've a file with 1000 lines in format below. I am looking for only col
> > 2 which is teka, deka and meka but if i do awk -F '{print $2}' it
> > gives me anything after space. How do i look only for the col 2 with
> > awk? please help.
>
> > mide/MC MIDE Sent teka 6009
> > mide/MC MIDE Templates deka 6009
> > test/test12 test/test 1 2 meka 6583
>
> > Thanks in Advance
> > shahb
>
> Awk works on records (normally lines) split into fields (normally
> separated by any contiguous sequences of any white-space). If you want
> awk to use something else as the field separator, you need to tell awk
> what that separator is. For example:
>
> awk -F'\t' '{print $2}' file
>
> would print the 2nd field in each record where the fields are separated
> by a single tab character.
>
> Ed.
Thanks it worked...
I was trying awk -F'\t' '{print $2}' file without the quotes and was
giving weired results.
Thanks Ed.
Re: simple grep/awk
am 13.09.2007 03:44:07 von Dummy
explor wrote:
> Hi Gurus,
> I've a file with 1000 lines in format below. I am looking for only col
> 2 which is teka, deka and meka but if i do awk -F '{print $2}' it
> gives me anything after space. How do i look only for the col 2 with
> awk? please help.
>
> mide/MC MIDE Sent teka 6009
> mide/MC MIDE Templates deka 6009
> test/test12 test/test 1 2 meka 6583
perl -lane'print $F[-2]'
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Re: simple grep/awk
am 13.09.2007 15:50:22 von Glenn Jackman
At 2007-09-12 05:23PM, "explor" wrote:
> Hi Gurus,
> I've a file with 1000 lines in format below. I am looking for only col
> 2 which is teka, deka and meka but if i do awk -F '{print $2}' it
> gives me anything after space. How do i look only for the col 2 with
> awk? please help.
>
> mide/MC MIDE Sent teka 6009
> mide/MC MIDE Templates deka 6009
> test/test12 test/test 1 2 meka 6583
If you want the 2nd-last field: awk '{print $(NF-1)}'
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry