Comparing Alphanumeric Variables in Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing Alphanumeric Variables in Shell Script
# 1  
Old 01-14-2010
Comparing Alphanumeric Variables in Shell Script

Can someone please help me out here?

I have strings similar to aafafaff45,29.34.942.45,edfdfafa that i want to compare to another similar string to check if they are the same. my script isn't working.

ONE="aafafaff45,29.34.942.45,edfdfafa"
TWO="ddfafagfa,87.57.942.45,afafafff"

if ONE is the same as TWO, the script i wrote is suppose to echo out a 0. but it is echoing out a 2.
# 2  
Old 01-14-2010
Code:
if [ "$ONE" == "$TWO" ]; then
 echo same
else
 echo different
fi

# 3  
Old 01-14-2010
Script ? Where ?
# 4  
Old 01-14-2010
Maybe you show your script so we can correct it. If the complete string should be tested you can use something like

Code:
ONE="aafafaff45,29.34.942.45,edfdfafa"
TWO="ddfafagfa,87.57.942.45,afafafff"
#TWO="aafafaff45,29.34.942.45,edfdfafa"

if [[ "$ONE" != "$TWO" ]]; then
        echo 1
else
        echo 0
fi

# 5  
Old 01-14-2010
Code:
#!/bin/sh

RESULTS=$(curl -s "http://1444.66.44.293:7760/datalocation?transaction_id=126454545454&account_number=45454183521&date_start=1262968108&date_end=1262968108&im=false" | sed 's/,//g')

EOUTPUT=$(echo 1,1,0,1041379200,18446744071500476416,REG,CDR,ORACLE,cdr,10.255.255.11 | sed 's/,//g')

#echo $RESULTS > /tmp/nagios_datalocation_results.txt
#echo $EOUTPUT > /tmp/nagios_datalocation_eouput.txt
#exit


if [[ "$RESULTS" != "$EOUTPUT" ]] ; then

        echo "2"
        exit 2
else
        echo "0"
        exit 0
fi

So basically, even though the contents of both $RESULTS and $EOUTPUT are the same, this shell script isn't recognizing that and is aborting with a 2. rather than a 0.
# 6  
Old 01-14-2010
please echo both the values and post the o/p.

Code:
echo "$RESULTS"
echo "$EOUTPUT"

if [[ "$RESULTS" != "$EOUTPUT" ]] ; then

        echo "2"
        exit 2
else
        echo "0"
        exit 0
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

2. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. Shell Programming and Scripting

Comparing dates in shell script

Hi All, I have a date variable say dt="2014-01-06 07:18:38" Now i need to use this variable to search a log and get the entries which occured after that time. (1 Reply)
Discussion started by: Girish19
1 Replies

4. UNIX for Dummies Questions & Answers

I want to compare to alphanumeric value in a unix shell script.

#!/bin/sh b= SERVER if ; then echo "hostname $a is same" ____________________________ (17 Replies)
Discussion started by: Nsharma3006
17 Replies

5. Shell Programming and Scripting

shell script for comparing two files

Hi, I have 2 files as below FILE1.dat co1|co2|co3 abnd|45.56|AZ dkny|30.2|PA sam|.23|VA FILE.CTL FILENAME|FILE1.dat NO OF RECORDS|3 CHECKSUM|75.99 Could you please help me to write a shell script to compare 1. TOTAL RECORDS from FILE1.dat with NO of RECORDS in FILE.CTL 2.... (8 Replies)
Discussion started by: dreamsportsteam
8 Replies

6. UNIX for Dummies Questions & Answers

Parsing alphanumeric variables

Hi All, I have files with a column which has values and ranges, for example colA colB ERD1 3456 ERD2 ERD3 4456 I want to have the following output colA colB colC ERD1 3456 3456 ERD2 526887 526890 ERD3 4456 4456 Being a newbie to... (2 Replies)
Discussion started by: alpesh
2 Replies

7. Shell Programming and Scripting

Comparing 2 file use c shell script

Hi all, I got 2 file : file1: file2: output: But , must write out in C shell.Anybody can help solve? (6 Replies)
Discussion started by: proghack
6 Replies

8. Shell Programming and Scripting

comparing two files using shell script

hi experts please help me to compare two files which are in different directory file1<file will be master file> (/home/rev/mas.txt} ex x1 x2 file2 <will be in different folder> (/home/rev/per/.....) ex x3 x4 the filesinside per folder i need to compare with master file and the files... (2 Replies)
Discussion started by: revenna
2 Replies

9. UNIX for Dummies Questions & Answers

shell script for comparing 2 files

Hi, how to read the 2 files and compare each other in shell script? i have 2 files test1 and test2, both files contains 20 character records.we have to compare file 1 records with file2, if exists then reject the record else we have to append it to test2 file. in file test1 around 100 single... (2 Replies)
Discussion started by: prashanth.spl
2 Replies

10. Shell Programming and Scripting

comparing content of 2 variables in script

hello how can i compare the content of two variables using the if or for loops. I have 2 variables which was formed as result of commands pass into them but i want to now compare the 2 contents and echo where their is a match for examples variable1=`cat file2` variable2=`cat file3` if #... (5 Replies)
Discussion started by: sam4now
5 Replies
Login or Register to Ask a Question