The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-13-2008
aemunathan aemunathan is offline
Registered User
  
 

Join Date: May 2008
Posts: 76
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
  #2 (permalink)  
Old 05-13-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by aemunathan View Post
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

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

  #3 (permalink)  
Old 05-13-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0