String compare in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String compare in shell script
# 1  
Old 11-29-2008
Question String compare in shell script

Iam trying to compare the string in if else... but some how its not working

following is the code

Quote:
if [ "${dbfiles[$l]}" -eq "${patchfiles[$k]}" ];
then
echo matched;
fi
On executing the above one its giving a error message ': bad number'

in the above parameter l & k are numbers and dbfiles and patchefiles are array

If i do echo ift working fine

echo ${dbfiles[$l]}

Iam trying to compare strings in array... any help on how it can be done.
# 2  
Old 11-29-2008
Hi,

-eq is meant to compare numbers. Try "=" or "=~" depending on what you
want to achieve. For further information:

Code:
man test

HTH Chris
# 3  
Old 11-29-2008
Quote:
Originally Posted by Christoph Spohr
Hi,

-eq is meant to compare numbers. Try "=" or "=~" depending on what you
want to achieve. For further information:

Code:
man test

HTH Chris

Thx it worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

2. Post Here to Contact Site Administrators and Moderators

Want a tcl script to compare a string in a file ignoring white spaces

Hi , I want a tcl script to search a string ignoring whitespaces in a .log file . It should correctly match . The string are as follows "Output-Maps 1 1 0 0 0" 1 and Active Intermediate-Maps 0 0 0 ... (1 Reply)
Discussion started by: kulua
1 Replies

3. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

4. Shell Programming and Scripting

Shell script to compare two files

I have two files; file A and file B. I need all the entries of file A to be compared with file B line by line. If the entry exists on file B, then save those on file C; if no then save it on file D Note :- all the columns of the lines of file A need to be compared, except the last two columns... (8 Replies)
Discussion started by: ajiwww
8 Replies

5. Shell Programming and Scripting

Shell Script to Compare Two Files

I have a directory with about 6 files that we receive regularly. these 6 files contain information for 3 different units, 2 for each unit. files related to a specific unit are named similarly with a change in number at the end of the file. the numbers should be sequential. for each grouping of... (3 Replies)
Discussion started by: scriptman237
3 Replies

6. Shell Programming and Scripting

String compare with list in shell script

Hi , I am new to shell scripting. below is my requirement : 1) while running my .sh i will pass a string 2) i have to extract a folder name under a /config folder 3) i need to compare a input string in the folder name list 4) if that is true i have to continue my job else i have to... (2 Replies)
Discussion started by: rajinavaneethan
2 Replies

7. Shell Programming and Scripting

how to compare two lines using shell script?

how to compare two lines using shell script? (1 Reply)
Discussion started by: suman_dba1
1 Replies

8. UNIX and Linux Applications

How to compare 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... (1 Reply)
Discussion started by: revenna
1 Replies

9. Shell Programming and Scripting

compare two tables using shell script

Hi, I want to compare two tables fieldwise using shell script. Can anyone help me regarding the same. The approach which i tried is to first move the two tables in simple txt file where each field is now seperated by space. But i can't retrive each field with "space" as a seperator b'coz there... (1 Reply)
Discussion started by: dtidke
1 Replies

10. Shell Programming and Scripting

shell script cant recognize if else compare

hi I face the problem the if else statement dint return correct result for me my script as below: #!/bin/ksh sqlplus -s /nolog <<EOF connect databaseuser/password column num new_value num format 9999 set head off select count(*) num from table1; exit num EOF if ; then echo "$?"... (6 Replies)
Discussion started by: jaseloh
6 Replies
Login or Register to Ask a Question