Articles

Return value of awk

October 5, 2005 at 02:36:17
Specs: Unix, 512

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



See More: Return value of awk

Report •


#1
October 5, 2005 at 06:59:45

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


Report •

#2
October 5, 2005 at 08:06:00

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



Report •

Related Solutions


Ask Question