help needed at awk function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help needed at awk function
# 1  
Old 06-03-2008
help needed at awk function

hi,

I am new to scripting and need your help to debug .

Here is my goal, I need to collect text,validate it and say if there is any error .below is the code


validate_fn()
{
awk ' ....
END {

if(condition)
return 0
else
return 1
}' "$3"
}

Script1=/usr(Path) #my main script
paramter1="$1"
parameter2="$2"

a = $(Script1 log -t "$parameter1" "$parameter2") (# to store the text that I will be validating )

if($(validate_fn $a)== 1)then
{
echo"** error**">$2
exit 1
}
fi

exit 0


Here

I am trying to send the text to the function and if the condition is met the present script has to exit 0 else it has to echo error and exit 1 but the script is always exiting with with '0'.

Last edited by rider29; 06-03-2008 at 11:55 AM..
# 2  
Old 06-03-2008
The $(...) construct captures the output, not the return code, of the awk script. Make it print a value, or use a different construct. The simple if command is the standard way to test an exit code.

Code:
if awk 'END { exit rand() }' </dev/null
then
  echo exit code from awk was 0
else
  echo exit code from awk was 1
fi

(My mawk demands that I use exit rather than return if I'm not returning from an awk function. That is probably more correct even if your awk doesn't have the same requirement.)

(The random function returns a number between 0 and 1, and it seems that it will always be truncated to an integer zero, but this is just a lousy example anyway.)
# 3  
Old 06-03-2008
ooh...

Here my present script is being called by a script, the deal is

My script (say script2) should exit out with 1 or 0.

Is there any other way?

so that

1) Get the text from script1 (Script1 log -t "$parameter1" "$parameter2")

2) validate it with the function (validate_fn )

3) echo error message depending on the result from the validation function
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

2. Shell Programming and Scripting

awk help needed

Hi Everyone, i have following in my file 1 2 3 4 5 6 . . 100 and now i want the output as 1 4 7 ..........so on..............97 100 (10 Replies)
Discussion started by: zozoo
10 Replies

3. UNIX for Dummies Questions & Answers

help needed for awk

Dear all, I am new to use unix. I run the following command and got the error. Anyone knows how should I modify the command. Thanks a lot! $ for chr in 'seq 1 23'; do awk 'BEGIN {print "T","pheno";}{print "M",$2}' out_${chr}.map > dat_${chr}.dat; done error message:... (2 Replies)
Discussion started by: forevertl
2 Replies

4. Shell Programming and Scripting

Help needed for understanding a function

There is a function called start: start() { echo -n $"Sending Startup Email: " echo "${RESTARTBODY}" | mutt -s "${RESTARTSUBJECT}" ${EMAIL} RETVAL=$? if ; then touch ${LOCKFILE} success else failure fi echo return ${RETVAL} } Can anyone explain what the bold part of the... (3 Replies)
Discussion started by: proactiveaditya
3 Replies

5. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

6. Shell Programming and Scripting

URGENT: Script/Function needed to read text property files in block wise

Hi, Iam in a need for a script/function in KSH where I want to read a text file (property file) in block by block. Here is the example: Heading Name Descripton Block Block1 Value1 Description Property Name Value Property Name Value Property Name Value Property Name Value Property Name... (7 Replies)
Discussion started by: ysreenivas
7 Replies

7. Shell Programming and Scripting

Oracle Function Needed

Dear Experts, Please find below the script in perl and can any body convert this script exactly in to oracle 9i fiunction which will return the required result same as perl. #!/usr/bin/perl $nof=@ARGV; @var2 = (); for($n=0; $n<$nof; $n++) { $filename = @ARGV; open... (3 Replies)
Discussion started by: shary
3 Replies

8. Shell Programming and Scripting

Help needed to Keep calling a function after every 5 seconds.

Hey guys.! Need some help.I want to write a script , which should be continuosly running and should keep calling a function after every say 5 or 10 seconds. I am done with almost all part of it, but figuring out how to keep the script continuosly running and how to keep calling a function after... (11 Replies)
Discussion started by: nua7
11 Replies

9. Shell Programming and Scripting

Help needed in function calling in a script

:confused:Hi , I have a script as shown below: rpttxt() { name="$*" awk '/'"${name}"'/ {print $2 $3"=" $4}' file.txt } xx = rpttxt "COL_HEAD_1" awk 'BEGIN {printf("%36s \n ","'"$xx"'")}' rpttxt() is a function..I want to store the final result of this function in... (3 Replies)
Discussion started by: jisha
3 Replies

10. Shell Programming and Scripting

Help needed in awk

Hi All, I am trying to manipulate a file using awk in UNIX. My file "test_file" is structured as follows: field1:field2:field3 field4:field5:field6 field7:field8:field9 My requirement is to calculate another field (which would be let's say sum of 2nd and third column and put as fourth... (4 Replies)
Discussion started by: Vikas Sood
4 Replies
Login or Register to Ask a Question