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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

If statement in unix

Reply to Message Icon

Name: roopa_arjunan
Date: August 18, 2005 at 02:54:06 Pacific
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



Sponsored Link
Ads by Google

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


0

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


0

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: If statement in unix

unix if statement www.computing.net/answers/unix/unix-if-statement/8122.html

Printing in Unix www.computing.net/answers/unix/printing-in-unix/6725.html

NEED TO PRINT HTML IN UNIX! HELP! www.computing.net/answers/unix/need-to-print-html-in-unix-help/2834.html