Computing.Net > Forums > Unix > If statement in unix

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

If statement in unix

Reply to Message Icon

Original Message
Name: roopa_arjunan
Date: August 18, 2005 at 02:54:06 Pacific
Subject: If statement in unix
OS: unix
CPU/Ram: unknown
Comment:

Hi,
I have a file report.txt which has the contents as:

SheetName|RecordName|FieldName|TableName|ColumnName|Change
Summary||2||No specification received for output file record|MODIFIED
Central Checks|R3002SPLDXVOLUME|F3002-VOL1-VOL-SRL-NUM|SUBMISSION|SERIAL_NUM|DEL
ETED
Suspense data|RC3310SUSPMIGXDATA||||ADDED
Suspense data|RC3310SUSPMIGXDATA|FC3310-RECORD-TYPE|||ADDED

and my unix code is:

#!/bin/ksh
set -x
cat report1.txt | while read LINE
do
recordname=`echo $LINE | awk -F"|" '{print $2}'`
change=`echo $LINE | awk -F"|" '{print $6}'`
if test ! "$recordname" || test "$change" = "ERROR"
then
echo "something"
fi
done
set +x

I am checking whether recordname field is empty or change field contains string "ERROR".
But it is giving error.
Tell me the reason

Roopa.A


Report Offensive Message For Removal


Response Number 1
Name: Luke Chi
Date: August 18, 2005 at 06:20:45 Pacific
Reply:

cat report.txt | while read LINE
do
recordname=`echo $LINE | awk -F"|" '{print $2}'`
change=`echo $LINE | awk -F"|" '{print $6}'`
if [ -z "$recordname" ] || [ "$change" = "ERROR" ]; then
echo "recordname is empty or change is ERROR"
fi
done


Luke Chi


Report Offensive Follow Up For Removal

Response Number 2
Name: roopa_arjunan
Date: August 18, 2005 at 21:58:36 Pacific
Reply:


Hi,
Still its not taking the value of change

read LINE
cat report1.txt
+ awk -F| {print $2}
echo SheetName|RecordName|FieldName|TableName|ColumnName|Change
recordname=RecordName
+ awk -F| {print $6}
echo SheetName|RecordName|FieldName|TableName|ColumnName|Change
change=Change
err=ERROR
[ -z RecordName ]
= ERROR ]


See in this last line its checking correctly for recordname but it is not doing for change.Please tell me why its not taking change field value.

Thanks

Roopa.A


Report Offensive Follow Up For Removal

Response Number 3
Name: roopa_arjunan
Date: August 22, 2005 at 05:44:36 Pacific
Reply:

Now my code is working
I am using case statement instead of if statement.

Roopa.A


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home



Results for: If statement in unix

unix if statement
    Summary: The if statement is exactly what you would think. It test one value against another, then performs actions based on that test. For example, in the following script: #!/usr/bin/ksh x=1 if [[ $x -gt 0 ]...
www.computing.net/answers/unix/unix-if-statement/8122.html

Printing in Unix
    Summary: Is there a way to print in "Landscape" format in Unix? I don't know if you need this info but here it is anyway: /home/narsman% uname -a OSF1 V4.0 1530 alpha Thanks, Narsman ...
www.computing.net/answers/unix/printing-in-unix/6725.html

NEED TO PRINT HTML IN UNIX! HELP!
    Summary: In UNIX nearly all files are text files. there is yet another utility called "rtf2txt" - see a pattern here ? - that will do the rtf to text conversion. Just slip it into the command line pipe previou...
www.computing.net/answers/unix/need-to-print-html-in-unix-help/2834.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History






Data Recovery Software