![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Check File Exists and compare to previous day file script | rbknisely | Shell Programming and Scripting | 3 | 02-07-2008 11:53 AM |
| compare file size from a output file from a script | moustik | Shell Programming and Scripting | 7 | 11-07-2007 10:17 AM |
| compare 2 file and print difference in the third file URG PLS | evvander | Shell Programming and Scripting | 3 | 09-24-2007 07:52 AM |
| File Compare and Create New File with Diff | guiguy | UNIX for Advanced & Expert Users | 7 | 02-28-2007 06:43 AM |
| How to compare prev day file to current day file | Smurtzy | Shell Programming and Scripting | 1 | 12-05-2001 07:33 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
read a file and compare
hi
how can i read a file using the unix script and check for one or more field value for a predefined status/value for example : the file contains the following text Name IP Address/Mask Type Connection Status mgmt-eth0(1) 10.7.225.5/24 mgmt Ethernet Up lo1(1) 127.0.0.1/8 mgmt Loopback Up i need to check the status column value whether it is Up. if its not it has to be logged in a separate file. thanks |
|
||||
|
Quote:
Code:
for line in `cat $file` do statusfield=`echo $line | tr -s " " | cut -d " " -f5` if [ $statusfield = "up" ] then echo " system is up" else ---- fi done |
|
||||
|
I'm sorry, but that's pretty tortured. Code:
awk 'NR==1 || $5 == "Up" { next; } { print }' file
Is the status field always the fifth field? What's there when it's not up? Are there supposed to be empty lines between the records? Is it okay to simply ignore the header line? (I have made reasonable assumptions to all of these in the above script, but feel free to check those assumptions. Respectively: yes, anything or nothing, no, yes.) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|