For Programmers: Free Programming Magazines  


Home > Archive > AWK > March 2006 > Awk to match two conditions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Awk to match two conditions
bshah@citadon.com

2006-03-30, 6:56 pm

Hi Gurus,
With your help i had a script which was successfully getting all
entries which had first col. ranges between 50 and 350. I need to
modify this to give me output where first entry ($1) will range between
50 and 350 and second filed matches between [a-d]* and [l-q]*
basically sencond field which starts with [a-d]* or [l-q]*

INPUT_FILE
-------------------
21516 desno
10522 tcos
7855 lis
7255 fla
7018 dusdsd
6640 ant
6580 kfddg
6462 megfi
6432 lnic


awk '$1 >= 50 && $1 <= 350 { total+=$1;print $2} END { print total "
MB" > "/dev/tty" }' INPUT_FILE> OUTPUT_FILE

Regards
tester

Janis Papanagnou

2006-03-30, 6:56 pm

bshah@citadon.com wrote:
> Hi Gurus,
> With your help i had a script which was successfully getting all
> entries which had first col. ranges between 50 and 350. I need to
> modify this to give me output where first entry ($1) will range between
> 50 and 350 and second filed matches between [a-d]* and [l-q]*
> basically sencond field which starts with [a-d]* or [l-q]*


Do you mean a literal * or just the letters? Try this...

$1 >= 50 && $1 <= 350 && $2 ~ /^[a-dl-q]/ { ... }


Janis

> INPUT_FILE
> -------------------
> 21516 desno
> 10522 tcos
> 7855 lis
> 7255 fla
> 7018 dusdsd
> 6640 ant
> 6580 kfddg
> 6462 megfi
> 6432 lnic
>
>
> awk '$1 >= 50 && $1 <= 350 { total+=$1;print $2} END { print total "
> MB" > "/dev/tty" }' INPUT_FILE> OUTPUT_FILE
>
> Regards
> tester
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com