Hi Gurus,
With your help i created an awk script which looks as below:
awk '$1 >= 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ { total+=$1;print $2}
END { prin
t total " MB" > "/dev/tty" }' temp_file> result_file
temp_file
--------------
52 tst1
75 tst2
44 tst3
63 tst4
This gives all the names whose first record is between 50 and 375 and
second record starts with e-k or r-z. Now i need to add third condition
as:
UID=`ldapsearch -x -h ldap uid=$2 mailhost | grep -c mailHost`; if [
$UID -eq 1 ]
if UID value is 1 then only put it in result_file else reject that
entry.
I tried below:
awk '$1 >= 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ && UID=`ldapsearch -x
-h ldap uid=$2 mailhost | grep -c mailHost`; if [ $UID -eq 1 ] {
total+=$1;print $2} END { prin
t total " MB" > "/dev/tty" }' temp_file> result_file
Gives an error.
Please help me to resolve this script.
If you have better solution than this please do let me know.
Thanks a lot
|
|
0
|
|
|
|
Reply
|
bshah (26)
|
4/26/2006 6:30:32 PM |
|
On 26 Apr 2006 11:30:32 -0700 in comp.lang.awk, bshah@citadon.com
wrote:
>Hi Gurus,
>
>With your help i created an awk script which looks as below:
>
>awk '$1 >= 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ { total+=$1;print $2}
>END { prin
>t total " MB" > "/dev/tty" }' temp_file> result_file
>
>temp_file
>--------------
>52 tst1
>75 tst2
>44 tst3
>63 tst4
>
>This gives all the names whose first record is between 50 and 375 and
>second record starts with e-k or r-z. Now i need to add third condition
>as:
>
>UID=`ldapsearch -x -h ldap uid=$2 mailhost | grep -c mailHost`; if [
>$UID -eq 1 ]
>
>if UID value is 1 then only put it in result_file else reject that
>entry.
Try:
awk UIDS="`ldapsearch -x -h ldap uid=$2 mailhost | grep -c mailHost`"\
'$1 >= 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ && UIDS == 1 { total+=$1;
print $2 }
END { print total " MB" > "/dev/tty" }' temp_file > result_file
Note after the closing `" there is a space before the opening ';
you can omit the \ and newlines and type this all as a single line;
also, awk UIDS="`...`" makes it an awk variable, only visible in awk;
UIDS="`...`" awk would make it an environment variable definition, but
not available in awk (just in case you thought that was a mistake).
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
fake address use address above to reply
|
|
0
|
|
|
|
Reply
|
Brian
|
5/1/2006 5:10:51 AM
|
|
Hi Brian,
I tried but it doesn't understand uid=$2. uid value is blank which
means UIDS doesn't take temp_file as input to UIDS. Any idea how to
resolve this under awk?
Regards
> Try:
>
> awk UIDS="`ldapsearch -x -h ldap uid=$2 mailhost | grep -c mailHost`"\
> '$1 >= 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ && UIDS == 1 { total+=$1;
> print $2 }
> END { print total " MB" > "/dev/tty" }' temp_file > result_file
>
> Note after the closing `" there is a space before the opening ';
> you can omit the \ and newlines and type this all as a single line;
> also, awk UIDS="`...`" makes it an awk variable, only visible in awk;
> UIDS="`...`" awk would make it an environment variable definition, but
> not available in awk (just in case you thought that was a mistake).
>
> --
> Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
>
> Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
> fake address use address above to reply
|
|
0
|
|
|
|
Reply
|
bshah
|
5/3/2006 5:04:01 PM
|
|
On 3 May 2006 10:04:01 -0700 in comp.lang.awk, bshah@citadon.com
wrote:
>> Try:
>>
>> awk UIDS="`ldapsearch -x -h ldap uid=$2 mailhost | grep -c mailHost`"\
>> '$1 >= 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ && UIDS == 1 { total+=$1;
>> print $2 }
>> END { print total " MB" > "/dev/tty" }' temp_file > result_file
>>
>> Note after the closing `" there is a space before the opening ';
>> you can omit the \ and newlines and type this all as a single line;
>> also, awk UIDS="`...`" makes it an awk variable, only visible in awk;
>> UIDS="`...`" awk would make it an environment variable definition, but
>> not available in awk (just in case you thought that was a mistake).
>I tried but it doesn't understand uid=$2. uid value is blank which
>means UIDS doesn't take temp_file as input to UIDS. Any idea how to
>resolve this under awk?
Misread your original intent; try:
awk '$1 >= 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ { total + =$1;
cmd = "ldapsearch -x -h ldap uid=" $2 " mailhost | grep -c mailHost";
cmd | getline uids; close(cmd); if (uids == 1) print $2 }
END { print total " MB" > "/dev/tty" }' temp_file > result_file
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
fake address use address above to reply
|
|
0
|
|
|
|
Reply
|
Brian
|
5/8/2006 12:51:39 PM
|
|
Hi Brian,
It gives syntax error:
awk: syntax error Context is:
>>> = 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ { total + = <<<
> Misread your original intent; try:
> awk '$1 >= 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ { total + =$1;
> cmd = "ldapsearch -x -h ldap uid=" $2 " mailhost | grep -c mailHost";
> cmd | getline uids; close(cmd); if (uids == 1) print $2 }
> END { print total " MB" > "/dev/tty" }' temp_file > result_file
>
> --
> Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
>
> Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
> fake address use address above to reply
|
|
0
|
|
|
|
Reply
|
bshah
|
5/11/2006 8:41:09 PM
|
|
bshah@citadon.com wrote:
> Hi Brian,
> It gives syntax error:
>
> awk: syntax error Context is:
>
>>>> = 50 && $1 <= 375 && $2 ~ /^[e-kr-z]/ { total + = <<<
>
Make that += not + =
Please don't top-post.
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
5/11/2006 10:56:36 PM
|
|
|
5 Replies
544 Views
(page loaded in 0.21 seconds)
Similiar Articles: Awk Script with multiple condition... - comp.lang.awkOn 26 Apr 2006 11:30:32 -0700 in comp.lang.awk, bshah@citadon.com wrote: >Hi Gurus, > >With your help i created an awk script which looks as below: > >awk '$1 >= 50 ... Problem With Multiple Field Separators - comp.lang.awkAwk Script with multiple condition... - comp.lang.awk Problem With Multiple Field Separators - comp.lang.awk retrieve script name - comp.lang.awk Awk Script with multiple ... awk script to split text file content to multiple files - comp ...Awk Script with multiple condition... - comp.lang.awk awk script to split text file content to multiple files - comp ... merge two files in awk - comp.lang.awk awk script ... Closing process on other side of pipe - comp.lang.awkHi all, I execute the following command, $ tail -f | On certain condition I want to exit from my_awk_script. But when I call exit() from my_awk_sc... efficiency in awk - comp.lang.awkAwk scripts are written for purposes of ease, portability ... or one if test that has a long string of >> conditions ... Isn't including the ``library'' functions by multiple ... concatenate multiple strings - comp.lang.awkNeed help with script/calculation - comp.databases.filemaker ... Awk Script with multiple condition... - comp.lang.awk concatenate multiple strings - comp.lang.awk Need ... script for telnet on port 25 - comp.lang.awkAwk Script with multiple condition... - comp.lang.awk script for telnet on port 25 - comp.lang.awk I need to do this > for multiple mail servers with for loop in the shell ... how to use script file in cmd line - comp.lang.awkI have two awk script, one is pre.awk #!/usr/bin/awk # BEGIN ... interested in another way to call it, as with GNU awk's multiple -f options... gawk -f pre.awk -f ... AWK command inside the shell script - comp.lang.awkAWK question - split string into variables - comp.unix.shell ... AWK command inside the shell script - comp.lang.awk awk script to split text file content to multiple ... passing awk variable to shell variable - comp.lang.awkEND{ print testvar }'` If the awk script needs to produce ... cat testvarfile` or (especially if you want to set multiple variables), assuming Bourne-style shell: awk ' .... Awk Script with multiple condition... - Application Forum at ...Awk Script with multiple condition... - awk . This is a discussion on Awk Script with multiple condition... - awk; Hi Gurus, With your help i created an awk script ... Awk Script with multiple condition... - comp.lang.awk | Computer GroupOn 26 Apr 2006 11:30:32 -0700 in comp.lang.awk, bshah@citadon.com wrote: >Hi Gurus, > >With your help i created an awk script which looks as below: > >awk '$1 >= 50 ... 7/25/2012 5:08:34 PM
|