awk correction


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk correction
# 1  
Old 10-01-2014
awk correction

Code:
if awk 'BEGIN{if('$RSS'>='1000')exit 0;exit 1}' ; then
     dowhatever
fi

the above code works great when i'm comparing numerical figures.

but when i try to do a string comparison, it does not work:

Code:
if awk 'BEGIN{ /'$RSS'/ ~ /DB01/ exit 0;exit 1}' ; then
    dowhatever
fi

can this code be fixed?

Last edited by SkySmart; 10-01-2014 at 02:18 AM..
# 2  
Old 10-01-2014
Quote:
Originally Posted by SkySmart
Code:
if awk 'BEGIN{if('$RSS'>='1000')exit 0;exit 1}' ; then
     dowhatever
fi

the above code works great when i'm comparing numerical figures.

but when i try to do a string comparison, it does not work:

Code:
if awk 'BEGIN{ /'$RSS'/ ~ /DB01/ exit 0;exit 1}' ; then
    dowhatever
fi

can this code be fixed?
Hello SkySmart,

One simple way is we can avoid the use of awk.

Code:
if [["$RSS" == "DB01" ]] #### Considering DB01 is a text, if it is a variable use "$DB01".
then
    dowhatever
fi

EDIT: Also with an awk approach.

Code:
echo $RSS
singh
 
if awk -vvar="$RSS" 'BEGIN{ if(var ~ /singh/) {exit 0} else {exit 1} }' ; then
echo "correct"
else
echo "Incorrect."
fi

Output will be as follows.

Code:
correct

Thanks,
R. Singh

Last edited by RavinderSingh13; 10-01-2014 at 02:36 AM.. Reason: Added an awk solution
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 10-01-2014
Regarding the awk proposal: that would yield an exit code of 0 also if RSS were a long string containing DB01 somewhere. To make it look for DB01 exactly, use sth like
Code:
RSS=DB01
awk -vvar="$RSS" 'BEGIN{ exit 1 - (var == "DB01")  }'

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While loop correction

I am checking if ssh is working fine on remote server proceed for next step until keep check ssh port, below is shell script. #!/bin/bash MON="SSH" x=1 while do echo "SSH Checking Status" nc 192.168.1.20 -w 2 done (3 Replies)
Discussion started by: learnbash
3 Replies

2. Shell Programming and Scripting

Perl Script date correction

Need assistance for the below script. Little details: based on the hours specified it calculates future or past date,time. This script works absolutely great . But at one point when i wante specify future date with hours at 1682 hours ...1 hours skips .Dont know why the calculation misses 1... (2 Replies)
Discussion started by: ajayram_arya
2 Replies

3. UNIX for Dummies Questions & Answers

Correction in Syllabus

Sir, I have the following modules to learn. The details of the modules in the syllabus published by the university are given below. There are some huge spelling mistakes in the syllabus. I have corrected few of them. Can u please quote the spelling mistakes in the syllabus if any and kindly... (1 Reply)
Discussion started by: achuthmama
1 Replies

4. Shell Programming and Scripting

small script correction

input cz1 87942437 87952030 M_001144992 0 + 87942537 87949664 0 3 710,114,2506, 0,2725,7087, script awk '{ n11 = split($11, t11, ",") n12 = split($12, t12, ",") for (i = 0; ++i < n11;) { s12 = $2 + t12 print $4"_xon"i, "\t",$4"_xon"i,"\t", $1,... (1 Reply)
Discussion started by: quincyjones
1 Replies

5. Shell Programming and Scripting

cron job - shell code correction

Hi I have a website that is having problem with cron jobs... I have a cron job set up to go to a page with this code... <? include('config.php'); if($_sys->bible_email_frequency == 'DAILY') { $u = new user(); $u->send_bible_email(); } ?> If i send my browser to this page... (2 Replies)
Discussion started by: whybelieve
2 Replies

6. UNIX for Dummies Questions & Answers

Extract data correction???

Hi I have file "test.txt" i need to extract the data as below from this file. /home/cvs/gkc ->awk -v RS= '{print $(NF-2),$(NF-1),$NF}' test.txt Buildfile: build.xml Buildfile: build.xml Created dir: /dist/advance/2.0.4/20060926-0413 awk: The field -1 must be in the range 0 to 199. ... (6 Replies)
Discussion started by: gkrishnag
6 Replies

7. UNIX for Dummies Questions & Answers

End of Error correction

I am being told by serveral different departmens that serveral of the products we use such as Oracle, IONA orbix 3.0, Veritas NetBackup and Tivoli Maestro are about to end support of Error Correction Support. Could some please help me understand what this actually means. Thanks Kristian (1 Reply)
Discussion started by: kristian
1 Replies
Login or Register to Ask a Question