Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hoe to check values in a file

Status
Not open for further replies.

zanzemaj

Programmer
Nov 2, 2006
35
NZ
I am using a ksh script. Please help me read and get values from this file called stat.txt:
Code:
Job information for Job ID '465' using a Traditional view


Job "PD1002_predefined" - 2007-06-21 20:32:18
    (ID 465)

Operation: ARCHIVE
    TDPID: 1
  Streams: 3


Stream  Client                              Size      Time Statcode
------  -------------------- ------------------- --------- --------
1       sldgpp01                       9,501,272  09:09:25        4
2       sldgpp02                 376,857,925,467  09:09:24        4
3       sldgpp03                       9,501,270  09:09:23       12

I need to check the values of Statcode, if I get a value of 0 or 4, then echo "Status Ok". If I get other values, say Statcode is 8 or 12, echo "Error" and Exit 1.

Any help would be great. Thanks.
 
And what have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This is my starting point:
Code:
awk '{print $5}' stat.txt
This produces:
Code:
ID


20:32:18







Statcode
--------
4
4
12
How do I get the values of Statcode (which for this file is 4,4,12 and check them, if I get a 12 or 8, message an error)
 
Hi

Based on your code this seems to be enough :
Code:
awk '$5==8||$5==12{print"error :",$5}' stat.txt
To check only values of the bottom "table", restrict the check to the values after the line composed only by dashes ( - ) and spaces ( ) :
Code:
awk '/^[- ]*$/{l=1}l&&($5==8||$5==12){print"error :",$5}'

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top