12-29-2011
Using Logical Expression in an AWK statement
I'm would to create a script that would give me the results below.
Please note the spaces in the log file are actually commas(",".)
Log file Data
HTML Code:
[TABLE]
0:00 21:15 899 43 31 12 25.39
0:00 21:20 736 34 19 15 35.39
0:00 21:20 776 41 28 13 66.65
0:00 21:20 777 43 31 12 15.44
0:00 21:20 899 44 32 12 96.6
0:00 21:20 126 40 27 13 95.44
0:00 21:20 130 37 23 14 95.44
0:00 21:25 736 35 20 15 96.6
0:00 21:25 775 35 20 15 36.65
0:00 21:25 776 41 28 13 96.65
0:00 21:25 780 43 31 12 95.44
0:00 21:25 891 35 20 15 46.08
0:00 21:25 896 49 39 10 95.44
0:00 21:25 899 43 31 12 95.39
0:00 21:30 691 37 23 14 75.19
0:00 21:30 736 37 23 14 95.38
0:00 21:30 764 43 31 12 55.37
0:00 21:30 776 40 27 13 95.44
0:00 21:30 777 47 36 11 96.65
0:00 21:30 780 44 32 12 76.65
0:00 21:30 783 34 19 15 95.44
0:00 21:30 891 35 20 15 96.08
0:00 21:35 736 37 23 14 25.44
0:00 21:35 776 40 27 13 15.44
0:00 21:35 778 40 27 13 35.34
0:00 21:35 780 44 32 12 96.65
0:00 21:40 685 40 27 13 95.39
0:00 21:40 691 41 28 13 96.38
0:00 21:40 777 46 35 11 95.44
0:00 21:40 780 43 31 12 95.44
0:00 21:40 882 34 19 15 75.39
0:00 21:40 891 38 24 14 95.89
0:00 21:40 896 49 39 10 80.44
0:00 21:45 782 38 24 14 96.34
0:00 21:45 882 35 20 15 96.65
0:00 21:45 900 37 23 14 95.19
0:00 21:50 685 40 27 13 95.39
0:00 21:50 689 41 28 13 96.65
[/TABLE]
I've tested the following individual scripts and I get the desired results.
Tested Scripts
HTML Code:
cat /log/per_111217.txt | awk -F, '{if ($9 >= 95 && $5 > 40 && <= 50)print $0}'
cat /log/per_111217.txt | awk -F, '{if ($9 >= 95 && $5 < 50)print $0}'
I would nowlike to Simplify it a bit more and require some assist before I attempt. Please note I'm running Solaris OS.
Simplified Not Yet Test
HTML Code:
{
cat /log/per_111217.txt | awk -F, '{if ($7 >= 95 && $4 <= 40)print $0}';
else if ( ($7 >= 95 && $4 > 40 && <= 50)print $0);
else if ($7 >= 95 && $4 < 50)print $0};
else "0 Found"
}
Desired Output
Result for 40 or less
|
0:00 21:40 882 34 19 15 95.39 |
0:00 21:40 891 38 24 14 95.89 |
Results for more than 40 but less than 50
|
0:00 21:30 777 47 36 11 96.65 |
0:00 21:30 780 44 32 12 97.65 |
Results for 50 or more
|
0:00 21:20 126 50 27 13 95.44 |
0:00 21:20 130 57 23 14 95.44 |
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
hi I have following if condition
line_by_line="0000000000000tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
if
then
echo "Exclusion criteria"
else
echo "Not exclusion criteria"
fi
above condition works perfectley but if i add one more logical condition... (3 Replies)
Discussion started by: mahabunta
3 Replies
2. Shell Programming and Scripting
Hi there, probably a really simple question to answer but i cant seem to find it
can I use a logical AND (&&) within a CASE statement ie (ps this is useless syntax but youll get the idea
case "$var1","$var2" in
'Billy' && 'Bobby')
... (1 Reply)
Discussion started by: hcclnoodles
1 Replies
3. UNIX for Dummies Questions & Answers
I have some geometric data (X Y) that is in the wrong scale. My raw data is in mills but it needs to be in tenths of a mil
I am pretty familiar with awk and sed
I want to use awk to divide $1 and $2 by .1
I'm just not sure of the syntax $1 and $2 are variables and .1 is fixed
simple... (3 Replies)
Discussion started by: awk_sed_hello
3 Replies
4. Shell Programming and Scripting
I'm pretty sure I already know the answer to this, but I want to make sure I'm not overlooking anything. I'm working on a log monitoring script and every 10 lines I want to display a summary of events. The thing is, there are a lot of possible events, that likely won't have happened, so I only want... (0 Replies)
Discussion started by: DeCoTwc
0 Replies
5. Shell Programming and Scripting
Hi
I want to send a status mail if daily or weekly or monthly batch completed or aborted. Here is the code.
if && &&
||
Else if &&
&& ||
Else if &&
&& ||
then
mailx –s “Status Report” sumone@sumthing.com
else
print ”try again”
Plz suggest the changes. (3 Replies)
Discussion started by: Avi
3 Replies
6. Shell Programming and Scripting
I have the following script:
For catching errors like:
But the regular expression ERROR*memory inside case doesn't seem to be working.
The output of bash -x scriptname is:
Please help (5 Replies)
Discussion started by: proactiveaditya
5 Replies
7. Shell Programming and Scripting
Please tell me how to nest logical expressions in bash. I would like to nest logical expressions for arguments of the "test" command on bash.
The following pseudo-code shows my intention.
// pseudo code
if (exp1 AND (exp2 OR exp3))
{
Output true;
}
else
{
Output false;
}
... (11 Replies)
Discussion started by: LessNux
11 Replies
8. Shell Programming and Scripting
Hi,
i want to check if a variable var1 is not a or b or c
pseudo code:
If NOT (var1 = a or var1 = b or var1 = c)
then
...
fi
I want to use POSIX complaint Korn shell, and for string comparison
For the following code, logical.sh
#!/usr/bin/ksh
var="j"
echo "Var : $var"
if ! { || ||... (12 Replies)
Discussion started by: ysrini
12 Replies
9. Shell Programming and Scripting
I do have a shell file where I call many unix commands . I would like to add a regular expression step in that shell file, where a text file, say Test.txt has to be openned and all the :'s should be replaced.
Basically apply the follwoing regular expression:
:%s/://g
to that particular text... (2 Replies)
Discussion started by: Lucky Ali
2 Replies
10. Shell Programming and Scripting
Below is what i have in my script.
htcount=$(curl -s --user tomcatstatus:tomcatstatus http://`hostname`.mypc.com:887/manager/jmxproxy?qry=Catalina:type=ThreadPool,name=\"http-nio-887\" |grep sBusy | cut -d ' ' -f2)
echo $htcount
if ; then
echo "more than 10"
else
echo "Less than 10"
fi... (6 Replies)
Discussion started by: mohtashims
6 Replies