LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-21-2008, 10:07 PM   #1
OldGaf
Member
 
Registered: Feb 2008
Posts: 47

Rep: Reputation: 15
Deleting lines based on comparing fields.....


Hi all,

I am not sure how to aproch this, or what to use ie. sed, awk, grep, all of the above....

I have many lines of text like below this in a file:



serverf2 /vol/serverv1/appl_some_application_instance_prod_sybdump019
1 Missing Files - 0 files on tape - 1 files purged

serverf2 /vol/serverv1/appl_some_application_instance_prod_sybdump019
2 Missing Files - 1 files on tape - 1 files purged

serverf2 /vol/serverv1/appl_some_application_instance_prod_sybdump019
6 Missing Files - 0 files on tape - 3 files purged

serverf2 /vol/serverv1/appl_some_application_instance_prod_sybdump019
3 Missing Files - 0 files on tape - 1 files purged

I need to compare the "missing files" with the "files on tape" and the "files purged"

In the first line, there is 1 missing file, but it has been purged so I don't care to see it.

In the last line, there are three missing files and only one was purged. I need to action this as there are 2 files unaccounted for.

There can be hundreds of lines like this and I want to find a way to strip out the unimportant one, or copy out the important ones. Is this too complicated for sed, awk etc?

Last edited by OldGaf; 02-21-2008 at 10:08 PM. Reason: spelling..... uh!
 
Old 02-21-2008, 10:57 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Code:
awk -vRS='' '{ if ( $3-$12 > 0 ) print $1, $3-$12}'
This very much depends on the data being consistently exactly as you say but something like that - it again sets the record separator to blank line, tests that there are more 'Missing Files' than 'files purged', and prints the server (first word of first line) and the value (Missing Files - files purged) or ignores them if all missing files have been purged.
 
Old 02-22-2008, 07:04 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
consistent with digiot's comment, be sure you have defined exactly what the logic (criterion) will be to delete a line.
 
  


Reply

Tags
awk, compare, deleting, grep, sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AWK - why fields go to seperate lines? korhan Linux - Newbie 2 03-01-2007 03:21 PM
awk to remove first 3 lines and print remaining $1, $2 fields phyx Linux - General 1 01-10-2007 05:21 PM
Unique lines based on specific fields. carl.waldbieser Programming 6 08-21-2005 02:26 PM
sql: highest value, comparing fields Ephracis Programming 6 06-01-2005 05:28 PM
Joining multiple lines and summing fields elconde Programming 1 02-13-2004 10:42 PM


All times are GMT -5. The time now is 11:29 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration