The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem in ksh script ( String comparison ) amarnath AIX 1 07-18-2006 03:40 AM
Problem in ksh script ( String comparison ) amarnath Shell Programming and Scripting 3 07-13-2006 09:14 AM
Problem deleting file with special character hart1165 UNIX for Dummies Questions & Answers 2 12-07-2005 07:29 AM
comparison problem ranj@chn Shell Programming and Scripting 8 11-05-2005 03:03 AM
rsync problem - space character in filename chief2 UNIX for Dummies Questions & Answers 3 09-24-2004 08:06 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-21-2003
Registered User
 

Join Date: Sep 2001
Location: Phoenix
Posts: 76
Stumble this Post!
character comparison problem

I have three lines in a log that I want to check to make sure that they say the following (mm/dd/yyyy and hh:mm:ss changes depending in when the log is generated):

'*** Testing file for mm/dd/yyyy'
'*** End of procedure! Time was: hh:mm:ss'
'*** End ***'

I did some sed and cut and ended up with something like this (the constant portion):
Code:
if [[ $first = '***            Testing file' ]] &&
   [[ $second = '***            End of procedure Time was:!' ]] &&
   [[ $third = '*** End ***' ]]; then
  do something
else
  handle error
fi
When I echo out the uncut lines (as is) compared to the cut lines, they match up to the point where I did the cut:

'*** Testing file for mm/dd/yyyy'
'*** Testing file for'
'*** End of procedure! Time was: hh:mm:ss'
'*** End of procedure! Time was'
'*** End ***'
'*** End ***'

Technically, my if-then statement matches the cut lines but the else ALWAYS gets executed even though the test echo statements I did seemt to match exactly to the dot...what is going on?? I can't figure it out. I thought it was some blanks somewhere but that did not appear to be the case. Anyone??

Gianni

added code tags for readability --oombera

Last edited by oombera; 02-20-2004 at 06:42 AM.
Forum Sponsor
  #2 (permalink)  
Old 02-21-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,443
Stumble this Post!
That's some very creative syntax you have there. I've never seen an "if" statement like that.

But look where you are checking $second. You have mispositioned the explanation point in your constant.
  #3 (permalink)  
Old 02-21-2003
Registered User
 

Join Date: Sep 2001
Location: Phoenix
Posts: 76
Stumble this Post!
The '!' in the wrong position was a typo but that didn't do anything..I'm still getting the error like it is not matching.

Also, is that wrong to write an if-else-then like that or you're just making an observation. I have tons of codes with that type of if-else-then...hehe

Thanks.
  #4 (permalink)  
Old 02-21-2003
Registered User
 

Join Date: Sep 2001
Location: Phoenix
Posts: 76
Stumble this Post!
Would be even better if someone can help me figure out how to check for the entire line content, keeping in mind that the pattern would still be:

*** Testing file for mm/dd/yyyy' '*** End of procedure! Time was: hh:mm:ss'

Would this make sense for pattern mm/dd/yyyy in the first line?

[0-1][0-2]/[0-3][0-9]/200[3-9]?

Thanks.
  #5 (permalink)  
Old 02-21-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,443
Stumble this Post!
If what you said was true, this should be working. This script
Code:
#! /usr/bin/ksh

first='*** Testing file'
second='*** End of procedure Time was:!'
third='*** End ***'

if [[ $first = '*** Testing file' ]] &&
   [[ $second = '*** End of procedure Time was:!' ]] &&
   [[ $third = '*** End ***' ]]; then
       echo ok
else
       echo not ok
fi
exit 0
will print "ok" when I run it. Give it it try and see if it works for you.

And try:
echo first = \"${first}\"
Maybe you have trailing blanks.
  #6 (permalink)  
Old 02-21-2003
Registered User
 

Join Date: Sep 2001
Location: Phoenix
Posts: 76
Stumble this Post!
It didn't work when I made the change as you've suggestd. Still causing error handling to be performed. It is only a problem on those lines where I did the cut. If I compare the line as is (last line) then it always executes successfully. This is why I am not sure if it is something else. I am not sure why the trimmed lines would be a problem though because what I trimmed and what I compared the trimmed lines to are identical as far as I can tell...
  #7 (permalink)  
Old 02-21-2003
oombera's Avatar
Have a day :|
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Stumble this Post!
Maybe you could put echo $first, echo $second and echo $third after "else" in the code just to make sure the values are what you intend them to be..
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0