Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

awk value return

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-20-2009
tal tal is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 14 June 2009, 5:41 AM EDT
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
awk value return

I have a script in awk and i have a unix shell script too ,and i want to call from the unix shell the awk script but that is returning a value according to what have been checked and found like boolean value in the awk script.
How do i do it?
Sponsored Links
    #2  
Old Unix and Linux 04-20-2009
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 1 September 2015, 9:23 AM EDT
Location: The Netherlands
Posts: 7,732
Thanks: 129
Thanked 549 Times in 516 Posts
It's not clear what you're trying to achieve, can you clarify your question with an example?

Regards
Sponsored Links
    #3  
Old Unix and Linux 04-20-2009
devtakh devtakh is offline Forum Advisor  
Unix Enthusiatic
 
Join Date: Oct 2007
Last Activity: 21 August 2013, 5:20 AM EDT
Location: Bangalore
Posts: 738
Thanks: 0
Thanked 7 Times in 7 Posts
the usual way to execute an awk script is

awk -f awkscript filename



cheers,
Devaraj Takhellambam
    #4  
Old Unix and Linux 04-26-2009
tal tal is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 14 June 2009, 5:41 AM EDT
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
an example

#!/bin/sh
awk -f input_check.awk strings.txt \\here i want the input_check.awk script to return a value that is boolean to the value will be used after this line with a if condition
awk -f messview.awk messages
awk -f report_maker.awk warn.txt
i=1;
new="yes"
for file in `ls`
do
file_check="part"$i;
if [ "$file" = "$file_check" ]
then
if [ "$new" = "yes" ]
then
cat $file_check > "reporta.txt"
new="no"
else
cat $file_check >> "reporta.txt"
fi
rm $file_check
(( i = i+1 ))
fi
done
Sponsored Links
    #5  
Old Unix and Linux 04-26-2009
devtakh devtakh is offline Forum Advisor  
Unix Enthusiatic
 
Join Date: Oct 2007
Last Activity: 21 August 2013, 5:20 AM EDT
Location: Bangalore
Posts: 738
Thanks: 0
Thanked 7 Times in 7 Posts
Quote:
Originally Posted by tal View Post
#!/bin/sh
awk -f input_check.awk strings.txt \\here i want the input_check.awk script to return a value that is boolean to the value will be used after this line with a if condition
awk -f messview.awk messages
awk -f report_maker.awk warn.txt
i=1;
new="yes"
for file in `ls`
do
file_check="part"$i;
if [ "$file" = "$file_check" ]
then
if [ "$new" = "yes" ]
then
cat $file_check > "reporta.txt"
new="no"
else
cat $file_check >> "reporta.txt"
fi
rm $file_check
(( i = i+1 ))
fi
done
retval=`awk -f input_check.awk strings.txt`

Make sure you return either a 0 or 1 in your awkscript. Then you can test in your unix script for 0 or 1.

cheers,
Devaraj Takhellambam
Sponsored Links
    #6  
Old Unix and Linux 04-26-2009
tal tal is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 14 June 2009, 5:41 AM EDT
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
But how can i return the value like this with awk?
Sponsored Links
    #7  
Old Unix and Linux 04-26-2009
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 1 September 2015, 9:23 AM EDT
Location: The Netherlands
Posts: 7,732
Thanks: 129
Thanked 549 Times in 516 Posts
Quote:
Originally Posted by tal View Post
But how can i return the value like this with awk?

Code:
 print "0"

or


Code:
print "1"

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
FTP Return 32 wilsonSurya IP Networking 3 10-10-2008 03:39 AM
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 06:44 AM
Return Key chapmana Shell Programming and Scripting 2 11-29-2006 03:52 AM
FTP return value Shaz UNIX for Advanced & Expert Users 7 06-11-2003 04:09 PM
the return value $? gusla Shell Programming and Scripting 3 12-08-2002 07:30 PM



All times are GMT -4. The time now is 09:30 PM.