LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to check for error in a particular file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-check-for-error-in-a-particular-file-678222/)

hchoonbeng 10-22-2008 01:12 AM

how to check for error in a particular file
 
Hi I try

for i in 1 to 100
do
#execute prog
content=$(</tmp/htx.flpb_sqrt0) #output file after prog executed
echo $content
done

Output file [default CON]: Successful Tests: 0 Numerical Errors: 0

I need to check if the numerical error is not 0 in the file. how to go abt using script and saving the output to a file?


thanks

jan61 10-22-2008 02:23 PM

Moin,

you can use sed to extract the interesting part of the file (I assume it has only this one line?):
Code:

num_errors=$(sed -r 's/.*Numerical Errors: ([0-9]+).*/\1/' /tmp/htx.flpb_sqrt0)
To check the value:
Code:

if test $num_errors -ne 0; then
  # error(s) occured, do something interesting
else
  # no error: do something else
fi

To write the error number to a file:
Code:

echo $num_error >output_file
Jan


All times are GMT -5. The time now is 02:36 PM.