comparing two strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting comparing two strings
# 15  
Old 09-21-2006
CPU & Memory perfect soln..

@ragha: try this..

Code:
if [[ $name -eq "Ragha" && $status -eq "Active" ]]
then
        echo success
fi

this working fine..... Smilie
# 16  
Old 09-21-2006
the problem is not with comparison as I initially thought. thanks for your reply. the problem appears with the code. can you look at the code and tell me what the problem could be. thanks
# 17  
Old 09-21-2006
Quote:
Originally Posted by ragha81
if i do what you said. i am getting syntax error like this

Code:
awk: syntax error near line 2
awk: bailing out near line 2

kindly help
pls post what you have changed your code to.
btw, what OS are you running under?
# 18  
Old 09-21-2006
I changed the code as you told like this

Code:
NR > 2 && NF  from NR > 2

but I get an error like this

Code:
awk: syntax error near line 2
awk: bailing out near line 2

# 19  
Old 09-21-2006
My Operating system is Solaris 5.8
# 20  
Old 09-21-2006
Quote:
Originally Posted by ragha81
I changed the code as you told like this

Code:
NR > 2 && NF  from NR > 2

but I get an error like this

Code:
awk: syntax error near line 2
awk: bailing out near line 2


Once again - pls post the ENTIRE script with the change.

also if you're running under solaris, change 'awk' to 'nawk'.
# 21  
Old 09-21-2006
please find the entire script below.

the problem seems to be like this

the variables SV_NAME, CC_NAME, CP_DISP_RUN_STATE gets read correctly the first time and the conditions are implemented fine. but what happens is, the condition gets checked the second time again, this time without even reading those variables from the file and gence has null values and the condition is satisified abd it displays error/giid when it shouldnt be doing so. I really appreciate your help. plz find the code below

[CODE}
#!/bin/ksh
#
# Purpose: - Turn on Workflow Monitor agents that are not in 'running'/'online' state

umask 000
export LT=`date +%Y%m%d_%H%M%S`

if [ -f ./WorkflowMon_env.rc ]
then
. ./WorkflowMon_env.rc
else
echo "FATAL: Error sourcing Workflow Server Components!" >> error.log
exit -1
fi

# Obtain the secure username and password (if it exists)
#
if [ -f "$BATCH_USER_DIR/batch_user.ksh" ]
then
TMPPWD=`pwd`
cd $BATCH_USER_DIR
. ./batch_user.ksh
RTNCD=$?
cd $TMPPWD
if [ $RTNCD = 0 ]
then
export SIEBEL_USERNAME=$USERID
export SIEBEL_PASSWORD=$PASSWORD
else
echo "FATAL: batch_user.ksh returned an error ($RTNCD)" >> error.log
exit -1
fi
else
echo "ERROR: batch_user.ksh does not exist, unable to source in variables" >> error.log
exit -1
fi
export temp_output=$BATCH_USER_DIR/WorkflowMon/log/temp_$LT.out
export input_file=$BATCH_USER_DIR/WorkflowMon/scripts/srvrmgr_input
i=0
echo ${#wfname[*]}
until [ $i -eq ${#wfname[*]} ]
do

$SIEBEL_ROOT/bin/srvrmgr -g $SIEBEL_GATEWAY -e $SIEBEL_ENTERPRISE -s $SIEBEL_SERVER -u n9912499 -p n9912499 -c "list component '${wfname[$i]}' show SV_NAME, CC_NAME, CP_DISP_RUN_STATE" -o "$temp_output"
sed -n "/^SV_NAME/,$ p" < $temp_output | sed "/rows* returned/,$ d" | awk '
NR > 2 && NF {n = split($0,arr," ")
printf("%s|",arr[1])
for( k = 2; k <=n-1;++k) printf("%s ",arr[k])
printf("\b|%s\n",arr[n]) }' > temp
old_IFS=$IFS
IFS="|"
while read SV_NAME CC_NAME CP_DISP_RUN_STATE
do
if [ "${wfname[$i]}" != "ALLTEL - WebOrders WorkActn" ]
then

if [ "$CP_DISP_RUN_STATE" != "${status[0]}" ]
then
echo success

fi
elif [ "${wfname[$i]}" = "ALLTEL - WebOrders WorkActn" ]
then

if [ "$CP_DISP_RUN_STATE" != "${status[1]}" ]
then
echo good
fi
fi
done < temp

((i=i+1))
done
[/CODE]

I get the following after set -x and not including && NF as you suggested. In that i Get an error as I posted earlier

Code:
2
+ 0< temp
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ [ ALLTEL - WebOrders WorkMon != ALLTEL - WebOrders WorkActn ]
+ [ down != Running ]
+ echo success
success
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ [ ALLTEL - WebOrders WorkMon != ALLTEL - WebOrders WorkActn ]
+ [  != Running ]
+ echo success
success
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ (( i=i+1 ))
+ [ 1 -eq 2 ]
+ /siebel/sble01/siebsrvr/bin/srvrmgr -g lfs6217q.alltel.com -e esble -s sble01 -u n9912499 -p n9912499 -c list component 'ALLTEL WorkMon24Hrs' show SV_NAME, CC_NAME, CP_DISP_RUN_STATE -o /siebel/sble01/siebfile/batch//WorkflowMon/log/temp_20060921_103109.out
+ sed -n /^SV_NAME/,$ p
+ 0< /siebel/sble01/siebfile/batch//WorkflowMon/log/temp_20060921_103109.out
+ awk
NR > 2 {n = split($0,arr," ")
printf("%s|",arr[1])
for( k = 2; k <=n-1;++k) printf("%s ",arr[k])
printf("\b|%s\n",arr[n]) }
+ sed /rows* returned/,$ d
+ 1> temp
+ old_IFS=|
+ IFS=|
+ set -x
+ 0< temp
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ [ ALLTEL WorkMon24Hrs != ALLTEL - WebOrders WorkActn ]
+ [ Running != Running ]
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ [ ALLTEL WorkMon24Hrs != ALLTEL - WebOrders WorkActn ]
+ [  != Running ]
+ echo success
success
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ (( i=i+1 ))
+ [ 2 -eq 2 ]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing Strings in ksh88

Hi I tried the following string comparison script in Ksh88 #!/bin/ksh str1='aC' str2='ABC' if then echo "Equal" else echo "Not Equal" fi Though str1 and str2 are not equal the script output says Equal . Please correct me Thanks (2 Replies)
Discussion started by: smile689
2 Replies

2. Shell Programming and Scripting

comparing strings as ints

Hi, So I got his code below. $year is a string of 2010,2011 etc. I guess I want to convert $year to an integer so I can do my if statement to see if the year string is greater than 2010? Or how could I do this? Right now I get a syntax error doing this. if; then do stuff fi (2 Replies)
Discussion started by: vsekvsek
2 Replies

3. UNIX for Dummies Questions & Answers

Strings comparing incorrectly

Hello I'm very new to Linux and shell scripting so I only know basic stuff. I'm making a script with the purpose of finding the longest string or word in a file. Here's what I got so far: #!/bin/bash longest="" for i in $(strings -n $1); do if ] then longest=$i fi done echo $longest... (4 Replies)
Discussion started by: SCB
4 Replies

4. Shell Programming and Scripting

Comparing strings with sed

Input: The the the the Output: not-same same What would be the sed command to do this? (7 Replies)
Discussion started by: cola
7 Replies

5. Shell Programming and Scripting

Comparing strings using nawk

Hello All Please I have got a file called DATE.tex which consist of 01-04-2008_12:00:00 01-04-2005_12:00:00 01-04-2003_12:00:00 01-04-2007_12:00:00 01-04-2002_12:00:00 01-04-2009_12:00:00 I want to use nawk to print out the dates >=01-04-2009_12:00:00 I tried this cat plnt.new |... (6 Replies)
Discussion started by: ganiel24
6 Replies

6. Shell Programming and Scripting

comparing two strings

hi All i am facing prob in comparing two strings that have two word. below is the code snippet. checkValidates="file validates" file3_name="file" if then echo "file" $file3_name "is validated successfully" fi when i run this i get the error as -bash: [: too many arguments ... (1 Reply)
Discussion started by: infyanurag
1 Replies

7. Shell Programming and Scripting

comparing 2 strings

hi i have 2 strings. i want to compare the strings. please help (2 Replies)
Discussion started by: satish@123
2 Replies

8. Shell Programming and Scripting

comparing strings

i have a string in a file which gets repeated number of times like below: rpttxt("abc") . . rpttxt("REP_TITLE") rpttxt("BOS_TITLE") . . . . and so on using awk or grep how can i comapre the string( as the second half keeps varying) and store it in a temporary variable? I am using the... (3 Replies)
Discussion started by: agarwal
3 Replies

9. Shell Programming and Scripting

Comparing Two Strings

Hi All, While I am trying to run below code I Am getting the exception like ./abs.sh: line 102: syntax error near unexpected token `then' ./abs.sh: line 102: ` then' The Code Snippet is: if then cat $file1 | sed -e... (8 Replies)
Discussion started by: Anji
8 Replies

10. UNIX for Advanced & Expert Users

Comparing strings

I have two strings a=Mar22 b=may21 how can I compare them Is this fine if then; . ... else .... fi or if then (2 Replies)
Discussion started by: yakyaj
2 Replies
Login or Register to Ask a Question