What was wrong ??? ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What was wrong ??? ksh
# 1  
Old 02-21-2006
What was wrong ??? ksh

I wrote this code and did not know what did I do wrong ??

## get the first line of this file
AFIRST=$(head -1 rss-cs-3423a-20051211-060001.dat)
#CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111 <--- this is a answer

## Third line of stat file
BTHREE=$(cat rss-cs-3423a-20051211-060001.stat | sed -n 3p)
#CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111
<--- this is a answer, both of them the same

### Compare AFIRST and BTHREE
if [[ $AFIRST = $BTHREE ]];
then
print "First record is matched"
else
print "First record is not matched"
fi



====

Why I get the answer is The First Record is not matched ??? syntax error ?
Please help me Smilie
# 2  
Old 02-21-2006
Your syntax is fine, but if your two variables differ by just one space then they are not matched. Try putting in some debug statements just before your if statement, e.g.....

echo AFIRST=[$AFIRST]
echo BTHREE=[$BTHREE]
# 3  
Old 02-21-2006
No it has to do with the pipe "|" symbols in the strings.

It is confusing the test. I don't know a way around it though. I've tried it myself with double quotes and single quotes around the strings but it still fails.

Perhaps perl is capable or there is a test in ksh I am just not aware of.
# 4  
Old 02-21-2006
Quote:
Originally Posted by DogDay
No it has to do with the pipe "|" symbols in the strings.

It is confusing the test. I don't know a way around it though. I've tried it myself with double quotes and single quotes around the strings but it still fails.

Perhaps perl is capable or there is a test in ksh I am just not aware of.
Sorry, but I have to disagree entirely. Here is proof at the ksh prompt...
Code:
$ AFIRST="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
$ BTHREE="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
$ if [[ $AFIRST = $BTHREE ]]; then echo "First record is matched"; else echo "First record is not matched"; fi
First record is matched

# 5  
Old 02-21-2006
Quote:
Originally Posted by Ygor
Sorry, but I have to disagree entirely. Here is proof at the ksh prompt...
Code:
$ AFIRST="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
$ BTHREE="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
$ if [[ $AFIRST = $BTHREE ]]; then echo "First record is matched"; else echo "First record is not matched"; fi
First record is matched

And I get to disagree too!

Code:
# AFIRST="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
# BTHREE="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
# if [[ $AFIRST = $BTHREE ]]; then echo "First record is matched"; else echo "First record is not matched"; fi
First record is not matched

sabercats said he is using ksh, what flavor of ksh are we talking about?
# 6  
Old 02-21-2006
how about this:
Code:
> AFIRST="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
> BTHREE="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
> if [ ! -z $(echo $AFIRST | grep "$BTHREE") ]; then echo "First record is matched"; else echo "First record is not matched"; fi

# 7  
Old 02-21-2006
Very roundabout but it works.
Code:
# AFIRST="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
# BTHREE="CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111"
# if [ ! -z $(echo $AFIRST | grep "$BTHREE") ]; then echo "First record is matched"; else echo "First record is not matched"; fi
First record is matched

And your grep for the BTHREE string in the AFIRST string will match any string that contains BTHREE within it. So its not a good test unless you are certain the data will never be out of those constraints.

Perhaps:

Code:
grep ^"$BTHREE"$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Number comparison in ksh on mac with -lt is giving wrong answer

I am trying to run following script in ksh on darwin 11.4.2: freeSpace=2469606195 spaceNeeded=200 ] && echo "no space" || echo "space available" ] && echo "no space" || echo "space available" "-lt" is giving wrong answer as "no space" Whereas '<' works fine. When I change the freespace... (4 Replies)
Discussion started by: sabitha
4 Replies

2. Shell Programming and Scripting

Can anyone tell me what's wrong here...

Here is my code.... just want to compare column 1 and 2 of file 2 with file 1 as standard file and print file 2 all contents with matched index value stored in $8 of file 1 awk 'NR==FNR{ A=$0;B++;next} {print A?$0 FS B: $0 FS "Not-Found" }' FS="\t" file1 file2 here B is not printing if... (19 Replies)
Discussion started by: Akshay Hegde
19 Replies

3. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

4. UNIX for Dummies Questions & Answers

[Solved] ksh script - can't figure out what's wrong

Hi! (I guess this could of gone into the scripting forum, but Unix for Dummies seemed more appropriate. Please note that I am not in school, so Homework doesn't seem appropriate either. You guys can let me know if you think otherwise.) I am following an exercise in a book on ksh scripting which... (2 Replies)
Discussion started by: sudon't
2 Replies

5. Shell Programming and Scripting

syntax of if condition in ksh is wrong

The syntax of 'if' conditionals in bash and ksh seems different. I am trying to check for a particular version using 'if' in ksh. This very simple syntax gives syntax error. I have tried many variants, but no go. Please correct the syntax. Later I will expand it to 'if' and 'else'. #!/bin/ksh... (8 Replies)
Discussion started by: nivedhitha
8 Replies

6. UNIX for Advanced & Expert Users

What am I doing wrong here?

I am working on a simple login ID check shell script that should prompt for a user ID then check to see if this user is logged on. Trying to get the hang of this stuff so I am thinking of my own little projects. #! /bin/sh echo "please enter a user name" read user if user=$user then... (3 Replies)
Discussion started by: jsk319342
3 Replies

7. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

8. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

9. Programming

What am I doing wrong!!!

Hi all, I'm just getting back in to C programming after some time and I thought I would start off with a simple XOR encryption program. However I'm having trouble getting it to work. The code in prompt() function works great when it is just placed in side of main() however I want to be able to... (5 Replies)
Discussion started by: WelshDave
5 Replies

10. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies
Login or Register to Ask a Question