Computing.Net > Forums > Unix > Return value of awk

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.

Return value of awk

Reply to Message Icon

Name: sivakarthik
Date: October 5, 2005 at 02:36:17 Pacific
OS: Unix
CPU/Ram: 512
Comment:

How to get the return value of a awk in a shell script?
awk -F['|'] '{print $6}' file.txt

In the above if the column 6 is null the script fails. How can I get the return value to do a check after this.

Thanks
Siva

Hi,
I'm trying to replace a column in a comma seperated file with a column in another file using sed/awk. Can anyone help me.

Thanks
Siva




Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: October 5, 2005 at 06:59:45 Pacific
Reply:

Null fields are perfectly valid and not considered an error by awk.  But you can force whatever exit code you want:

awk -F['|'] '{
 if ($6=="")
    exit 1
 else
    print $6}' file.txt

awkstatus=$?

if [ $awkstatus -ne 0 ] ; then
   echo "awk exited with status code of $awkstatus"
fi

awk exited with status code of 1


0

Response Number 2
Name: sivakarthik
Date: October 5, 2005 at 08:06:00 Pacific
Reply:

Okay, great. Thanks.

Siva

Hi,
I'm trying to replace a column in a comma seperated file with a column in another file using sed/awk. Can anyone help me.

Thanks
Siva



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: Return value of awk

awk return value www.computing.net/answers/unix/awk-return-value/7667.html

get value of 200th field by awk www.computing.net/answers/unix/get-value-of-200th-field-by-awk/7175.html

awk help www.computing.net/answers/unix/awk-help/7726.html