character comparison problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers character comparison problem
# 8  
Old 02-21-2003
Quote:
Originally posted by giannicello
It didn't work when I made the change as you've suggestd.
Please reread my post. I made two suggestions. One was to try the script that I posted. This is to see if your ksh is different than mine.

My second suggestion was indeed a change to your script. But I didn't expect that tossing in an a single echo statement would fix anything. The idea is that you will look at the output from the echo statement. If you did not cut it exactly right, you might have left one or more trailing blanks. A trailing blank will be visable since it will appear before the double quote.
# 9  
Old 02-24-2003
I tried your script and it says ok. I also know that there are no trailing blanks because in my cut statement, I played around with the character positions to cut to get exactly the strings to show (example):

lines=$(wc -l < $logfile)
line1=$(sed -n -e "$(($lines - 2))p" $logfile)
first=`echo "${line1}"|cut -c1-21` # played with this number <--
line2=$(sed -n -e "$(($lines - 1))p" $logfile)second=`echo "${line2}"|cut -c1-18`# played with this number <--
line3=$(sed -n -e "${lines}p" $logfile)
third=`echo "$line3"|cut -d" " -f1`

The number above are not exact for this example but it gives you an idea that I did play with it to get it to cut where I want it to cut and I even echoed out the statement before I did the if-then comparison:

echo out

echo "$line1"
echo "$first" #<--??
echo "$line2"
echo "$second" #<--??
echo "$line3"
echo "$third" #<--matched

In my if-then statement I did the comparision:

if [[ $first = '*** Testing file' ]] &&
[[ $second = '*** End of procedure Time was:!' ]] &&
[[ $third = '*** End ***' ]]; then
do something
else
handle error
fi

Hope this explains my confusion...and thanks again for looking at this with me.

Gianni
# 10  
Old 02-24-2003
Here is something to try...where you have:
Just before the if statement, try this:
third="${third%%*( )}"
but with all three variables. There is a single space inside the parentheses.
# 11  
Old 02-25-2003
Sample log output from another log file...

before - echoed out as is (without your suggestion (the website doesn't show all the blanks after the **** and before the first word though):

**** Test file processed for 02/24/2003 completed.
**** Datetime: Tue 02/25/2003 10:59:20
******************************************************************************

after - using your suggestion (echoed out w/suggestion as is, and then after I cut the lines). The space between the **** and the word Test reduced to 1 blank character versus 10 or so:

**** Test file processed for 02/24/2003 completed.
**** Test file processed for
**** Datetime: Tue 02/25/2003 10:59:20
**** Datetime: Tue
******************************************************************************
******************************************************************************

If I compare just the last line (even with the cut command) script executes find and return 0.
If I compare the first two lines (&&), it fails every single time.

Not sure what is happening...to me the characters match character for character.
I don't know what is causing this behaviour.
Grazie.

Gianni
# 12  
Old 02-25-2003
Copy your if statment and then edit it so that a line like this:
if [[ $first = '*** Testing file' ]] &&
becomes like this:
Xfirst='*** Testing file'
and do that for Xsecond and Xfirst as well. Make very sure that the constant is exactly the same as in the if statement. Put the new lines in front of the if statement. And after them put 6 lines like this:
echo the length of first is ${#first}
echo the length of Xfirst is ${Xfirst}

and so on with the other 4. This will show you how long the variables are. And how long the constants are. Something has got to be off.
# 13  
Old 02-26-2003
Thanks for your suggestion. I did the character count as you've recommended and the number matched (comes back as expected).

before cut:
50
38
78

after cut:
28
18
78

I even copied and pasted the expected text to compare and it still would not match up...

I figure I'll just grep for the messages line by line and if it exist set a flag to 'y' for each line and at the end do the if 'y' && 'y' && 'y' check...seems lame but this seems to be my only option...it still bugs me that I have to do this versus my original plan so if anyone can figure it out I'd appreciate it.

Have you tried to create a file with, say 10 lines, and then do the cutting like I did and compare cut lines to expected message?? I'd be interested in seeing what others get. If I don't cut (last line), script finished fine, if I cut/trim a line then the cut lines never pass.

Gianni
# 14  
Old 02-26-2003
There were supposed to be 6 numbers, not three. The idea is to compare that number of characters in first with the number of characters in Xfirst, where Xfirst was carefully set to the constant in the first part of the if statement. And so on for the other two. Something must not match.

I have tried to reproduce your failure, but I can't. It always works for me.

Try breaking the if statement into 3 separate if statements. Then you can see which of the 3 items is off.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in string comparison

guys , i am using inotify for monitoring one directory to check core file generation , my snippet of code is follows #!/bin/bash DIR=$1 inotifywait -q -e create -m $DIR | while read path events name; do if ]; then echo "Now I am going to do something with $name in directory $path."... (5 Replies)
Discussion started by: baker
5 Replies

2. Shell Programming and Scripting

awk Help - Comparison Operator problem

Hi, I've tried searching through the forum but I've drawn a blank so i'm going to post here. I'm developing a number of checks on a CSV file, trying to find if any are greater than a max limit. I'm testing it by running it from a command line. The file I'm testing has 8 records. When I... (3 Replies)
Discussion started by: Tmart
3 Replies

3. Shell Programming and Scripting

Problem with character by character reading

Hi friend, i have the following problem: when i am writting the below command on the command prompt , its working. while read -n 1 ch; do echo "$ch" ; echo "$ch" ; done<file_name.out. but when i am executing it after saving it in a ksh file, its not working. Please helppppppppp .. thankss... (18 Replies)
Discussion started by: neelmani
18 Replies

4. Shell Programming and Scripting

String comparison problem

Hi, can someone please help me!!! urgent! I have a strange issue here. I grep for 2 strings from a txt files and compare the string value. Though the string values are the same, they are compared as different values. Please help Case-1 -------- Here I grep for 2 different field values... (3 Replies)
Discussion started by: vani123
3 Replies

5. UNIX for Dummies Questions & Answers

character-by-character comparison of strings

This might be a dummy question, but is there a command in UNIX that compare two strings character-by-character and display the difference? ---------- Post updated at 11:25 AM ---------- Previous update was at 10:32 AM ---------- Or probably what I'm looking is how to break a string into... (3 Replies)
Discussion started by: Orbix
3 Replies

6. Shell Programming and Scripting

Uppercase/lowercase comparison of one character per line with awk??

Another frustrating scripting problem from a biologist trying to manipulate a file with several millions line. For each of the line I need to compare the uppercase A or C or G or T with the lowercase a or c or g or t. If there are more uppercases, a + should be added to a new column, otherwise a -... (10 Replies)
Discussion started by: ivpz
10 Replies

7. Shell Programming and Scripting

problem in string comparison in shell programming

Hello, was just wondering how to compare strings in unix? I mean as in C there is a function strcmp() in string.h, is there any function in unix for that? I tried using if and all such variations but didn't succeed. Any help would be appreciated. Thanks in advance :) (9 Replies)
Discussion started by: salman4u
9 Replies

8. AIX

Problem in ksh script ( String comparison )

hi , i am trying to compre two strings if ] or if ] when the length of var1 is small (around 300-400 char ) it works fine but when it is large (around 900-1000 chars) it fails is there any limitations for this type of comparison ??? (1 Reply)
Discussion started by: amarnath
1 Replies

9. Shell Programming and Scripting

Problem in ksh script ( String comparison )

hi , i am trying to compre two strings if ] or if ] when the length of var1 is small (around 300-400 char ) it works fine but when it is large (around 900-1000 chars) it fails is there any limitations for this type of comparison ??? (3 Replies)
Discussion started by: amarnath
3 Replies

10. Shell Programming and Scripting

comparison problem

Hi, Is there any limitation on the no of characters to be compared using the if statement in Unix. We had an issue while comparing the following two nos. var1=20051031222900 & var2=20051101003545. The last six dgits are the time stamp for a day. The if statement is like this: if then move... (8 Replies)
Discussion started by: ranj@chn
8 Replies
Login or Register to Ask a Question