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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Column value in a compare statement.

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
0
0
CA
Hello All:

I have a spooled file backup.txt with content in the following format:
LASTBACKUP NUMDAYS
------------------ ----------
11-MAR-10 21:01:15 46

I will like to compare the value in the NUMDAYS column in a shell script. My question is:

1) how can I get the value "46" in a shell script assigned to a variable "i"? (note this could be any value) so that I can say:

if i > 0
cat backup.txt | mailx 'Back did NOT complete last night' backup@dbas.com
else
end if


Thanks for your time
 
A starting point:
Code:
i=`awk 'NR==3{print $3;exit}' backup.txt`

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thanks PHV:

However, this did not work
#!/bin/ksh
i=`awk 'NR==3{print $3;exit}' backup.txt`
echo $i


Could you explain the code for me please.
 
this did not work
What happens ?
Any error message ?
Computer crash ?
Unexpected result ?
...
Below is the result of my test:
> cat backup.txt
[tt]LASTBACKUP NUMDAYS
------------------ ----------
11-MAR-10 21:01:15 46[/tt]
> i=`awk 'NR==3{print $3;exit}' backup.txt`
> echo $i
[tt]46[/tt]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Mine just displays blank:
>more backup.txt

LASTBACKUP NUMDAYS
------------------ ----------
11-MAR-10 21:01:15 46


>i=`awk 'NR==3{print $3;exit}' backup.txt`
>echo $i
>
 
And this ?
Code:
 i=`awk 'N[!]F[/!]==3{print $3;exit}' backup.txt`

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you. This works:

i=`awk 'NF==3{print $3;exit}' backup.txt`

Could you give a brief explanation?

Again, thanks
 
NF==3 -- when there are 3 fields on the line...
{ print $3 ; exit } -- print the third field, and exit, processing no further input.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top