Return value from awk.

Return value from awk.

Post by Ed Jaroc » Tue, 06 Feb 1996 04:00:00



Does anyone know how to send a return code from awk back to the
shell?  I have been looking in my book all day and I can not find
an example.  I have found examples of return codes back to awk from
other awk functions but no examples of awk sending a value back out
to the shell.  Any help would be great.

Ed Jaroch

 
 
 

Return value from awk.

Post by Bill Marc » Wed, 07 Feb 1996 04:00:00




Quote:>Does anyone know how to send a return code from awk back to the
>shell?  I have been looking in my book all day and I can not find
>an example.  I have found examples of return codes back to awk from
>other awk functions but no examples of awk sending a value back out
>to the shell.  Any help would be great.

You can use 'exit n'  which gives a return code in $? or $status depending
on your shell, or you can send awk's output to a shell variable, like
variable=`awk 'commands' filename`
or
set variable=`awk 'commands' filename`

 
 
 

Return value from awk.

Post by susan cassi » Fri, 09 Feb 1996 04:00:00




>Does anyone know how to send a return code from awk back to the
>shell?  I have been looking in my book all day and I can not find
>an example.  I have found examples of return codes back to awk from
>other awk functions but no examples of awk sending a value back out
>to the shell.  Any help would be great.

>Ed Jaroch


If you mean just an exit status, you can use the awk exit statement, like so:
if (nawk '{total += $1} END {print total
if (total > 250) exit 0
else exit 1}' <testin >testout); then
echo "exited with 0 status"
else
echo "exited with non-zero status"
fi

If you mean some other kind of output value, then other than having
awk output to a file and reading the file contents, you can only
place the standard output into a variable.  For example:
file testin looks like:
21      12
46      23
87      42
93      99
32      42

The awk script looks like:
VAL=`nawk '{total += $1} END {print total}' <testin`
echo 'VAL is now ' $VAL

This script results in the output:
VAL is now  279

Hope this was clear and answers your question.
--
Susan Cassidy

 
 
 

1. Getting AWK to return a value

I am currently writing a program which uses awk to determine if a few
simple conditions are met in a file.  I have searched trrough the documentation
but cannot seem to find anything on how to get awk to return values.

It would be nice if I can force awk to return with a certain exit code or
even change a varaible.  Is this possible?

Thanks in advance.

--
--
Chris Shudes

Tulane University, New Orleans

2. Icons never stay where placed

3. Default return value for when return() is not explicitly used on SC5.0

4. 2.8 to 2.9 - any reason

5. reliability of ftp return value

6. Cachefs testing

7. Analyzing return value

8. SNMP, Kerberos

9. Return Value 255 in Shells

10. getting the return value of a command executed on another host

11. Awk to average float values

12. Returning values to a shell script?

13. can a script return a value other than exit status