LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Deleting lines based on comparing fields..... (http://www.linuxquestions.org/questions/programming-9/deleting-lines-based-on-comparing-fields-622941/)

OldGaf 02-21-2008 10:07 PM

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?

slakmagik 02-21-2008 10:57 PM

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.

pixellany 02-22-2008 07:04 AM

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


All times are GMT -5. The time now is 11:10 AM.