awk value return


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk value return
# 8  
Old 04-26-2009
To be more preciser, the above statements echo the return code on the screen. The way to get the return code with the above statements in your script is:

Code:
retval=`awk -f input_check.awk strings.txt`

To return an exit code you can use the exit statement of awk:

Code:
exit(ReturnCode)

The return code can then be retrieved with:

Code:
retval=`echo $?`

# 9  
Old 05-03-2009
GNU nano 2.0.6 File: union.sh

#!/bin/sh
error=`awk -f input_check.awk strings.txt`
if [ "$error" = "ok" ]
then
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" GNU nano 2.0.6 File: union.sh

#!/bin/sh
error=`awk -f input_check.awk strings.txt`
if [ "$error" = "ok" ]
then
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
fi


new="no"
else
cat $file_check >> "reporta.txt"
fi
rm $file_check
(( i = i+1 ))
fi
done
fi
======================

I have this script now and the problem that if i want that the variable will get the value i need to do the command echo $error and then it prints the value of error too which i do not want to happen.
How can i avoid printing its value?
# 10  
Old 05-03-2009
Don't confuse with the last replay ,i posted the script twice ,start reading from the second "#!/bin/sh"
# 11  
Old 05-04-2009
In the case of the awk exit mode it allways returns 0 ,how can i make the script return a value like i want?
# 12  
Old 05-04-2009
Quote:
Originally Posted by tal
In the case of the awk exit mode it allways returns 0 ,how can i make the script return a value like i want?
As Franklin52 mentioned,

Code:
exit somenumber  (in your awk script)
ret=`echo $?`

( in the shell script)

Can you paste your awk script also?


cheers,
Devaraj Takhellambam
# 13  
Old 05-04-2009
BEGIN{ error="false";line=1;
}
{
check_count=split($0,count," ");
if (check_count<=3)
{
printf("Not enough sub strings in line %d should have method ,figures of row and count syntax and at least on$
error="true";
}
if ($1!="row"&&$1!="all")
{
printf("Bad name of words appearance metrhod on line %d, should be "all" or "row"\n",line);
error="true";
}
digits[1] = 0;
digits[2] = 0;
len[1] = split( $2, arr1 ,"" )
len[2] = split( $3, arr2 ,"" )
for ( i = 1; i <= len[1]; i++ )
if (( arr1[i] + 0 ) == arr1[i] )
digits[1]++
for ( i = 1; i <= len[2]; i++ )
if (( arr2[i] + 0 ) == arr2[i] )
digits[2]++
for (i=1;i<=2;i++)
{
if (i==1)
str="row";
else
str="all";
if ( len[i] != digits[i]||digits[i]<0 )
{
printf("Invaild value for the %s field on line %d should be numeric and equal or great from 0\n",str,line);
error="true";
}
}
}
END {exit(error);
}
# 14  
Old 05-04-2009
Don't use a literal "true" or "false" as a return value but a 0 for true and another number for false.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return path of specific tag using awk

The below awk is used with the attached index.html and matches the specific user id in the sub portion with path of /rundb/api/v1/plugin/49/. The command does run but the output is blank. Something changed in the file structure as it used to work. So using the first line in the output: ... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

awk command to return only field with a number in it

What is an awk command to print only fields with a number in it?? Input file....... S,S,S,S,S,S,S,S,S 001S,S,S,S,S,S,S,S,S 00219S,23S,24S,43S,47S,S,S,S,S 00319S,10S,23S,41S,43S,47S,S,S,S 00423S,41S,43S,46S,47S,S,S,S,S 00510S,23S,24S,43S,46S,S,S,S,S 00610S,23S,43S,46S,47S,S,S,S,S... (2 Replies)
Discussion started by: garethsays
2 Replies

3. Shell Programming and Scripting

awk - Print column number that return value comes from

I have the following awk script that I am using to find the max value in the file and print results. awk 'BEGIN {MAX=-1E100} {for (x=2; x<=NF; x++) if ($x>MAX) {MAX = $x; C1 = $1}} END {print substr(C1,1,11), substr(C1,13,4), substr(C1,18,2), MAX}' ABC* Input (ABC*) ... (6 Replies)
Discussion started by: ncwxpanther
6 Replies

4. Shell Programming and Scripting

awk return number of entries

I have a string with the following information and want to return the number of entries enclosed by <> in awk <stdin>: N = 441 <0.369000018/0.569000006> <0.369000018/0.569000006> <0/1> (7 Replies)
Discussion started by: kristinu
7 Replies

5. UNIX for Dummies Questions & Answers

return a specific row using awk

Hello, I am using awk to process a file, and need to return a row that meets specific criteria. awk 'BEGIN{sets variables} {processes file, updates variables} END{need to print a row that meets the criteria in one of the variables} I have tried code in the END block like {print NR==var}... (1 Reply)
Discussion started by: badPuppy
1 Replies

6. Shell Programming and Scripting

Awk return variable

Hi I have 2 working script, now i'd like to get the return value from the first and give it to the 2 script (both script work correctly if I run it separately). so i think the problem is only the first line in the way i pass the variable. in the final the "print lst", is just to check the... (2 Replies)
Discussion started by: Dedalus
2 Replies

7. Shell Programming and Scripting

Return Awk Variable to Shell

I'm a bit stuck in getting variable from awk to shell. I tried searching but most of them showing to assign to shell variable via.. VAR=`echo $line | awk -F: '{print $1}'` which is correct ofcourse My problem is multiple assignments of variable like this one. The above solution will give... (10 Replies)
Discussion started by: ryandegreat25
10 Replies

8. Shell Programming and Scripting

Function's return value used inside awk

I have a file with the record of person: cat > $TMP/record.txt John Torres M Single 102353 Address Mark Santos M Maried 103001 Address Carla Maria F Maried 125653 Address #!/bin/ksh ManipulateID(){ ... return 0; ... #or return 1; } cat $TMP/record.txt | awk 'BEGIN {printf... (4 Replies)
Discussion started by: Orbix
4 Replies

9. Shell Programming and Scripting

Help: return values from awk

Hi. I have a script like this: nawk 'BEGIN {FS=","; TOT1=0; REJ1=0;} { if($7=="TOTAL") { TOT1=TOT1 +$8} if($7=="REJS") { REJ1=REJ1 +$8} }' FILE_123.dat and... (1 Reply)
Discussion started by: mrodrig
1 Replies

10. Shell Programming and Scripting

Carriage return on long awk operation

hello all I have long awk function that doing manipulations on text file but when I write the out put to new text file I have carriage return between 2 print commands How can I avoid this ? Here is my awk : echo $f | awk... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question