Compare two outputs/files based on criterias


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare two outputs/files based on criterias
# 1  
Old 08-09-2011
Compare two outputs/files based on criterias

Hello,
I currently have a script that outputs to a file that contains the output below. It runs every X minutes. I would like to compare the first run against the second but only output if the minutes column is less than its original or if anything else changes. Thanks for the help.

Original
Code:
http://someurl.com,Name,1 type,16 minutes
http://somurl1.com,Name1,1 type,20 minutes
http://someurl2.com,Name2,1 type,18 minutes
http://someurl3.com,Name3,2 type,16 minutes

New
Code:
http://someurl.com,Name,1 type,30 minutes
http://somurl1.com,Name1,1 type,5 minutes
http://someurl2.com,Name2,2 type,20 minutes
http://someurl3.com,Name3,2 type,5 hours
http://someurl4.com,Name4,2 type,yesterday
http://someurl5.com,Name5,2 type,30 minutes

So it would find and output the format below:

Code:
http://somurl1.com,Name1,1 type,5 minutes
http://someurl2.com,Name2,2 type,20 minutes
http://someurl5.com,Name5,3 type,30 minutes


Last edited by tworkemon; 08-09-2011 at 12:21 PM.. Reason: fix formating
# 2  
Old 08-10-2011
Code:
awk -F, '
  function to_min(val) {
    if (val ~ /yesterday/)  return  24*60
    else if (val ~ /hours/) return +val*60
    else                    return +val
  }
  NR == FNR { a[$1$2$3] = $4 }
  NR != FNR && (!($1$2$3 in a) || to_min(a[$1$2$3]) > to_min($4))
' FILE1 FILE2

I believe your want this line too:
Code:
http://someurl4.com,Name4,2 type,yesterday

This User Gave Thanks to yazu For This Post:
# 3  
Old 08-10-2011
Thanks will give it a shot. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two files based on column

Hi, I have two files roughly 1200 fields in length for each row, sorted on the 2nd field. I need to compare based on that 2nd column between file1 and file2 and print lines that exist in both files into separate files (I can't guarantee that every line in file1 is in file2). Example: File1: ... (1 Reply)
Discussion started by: origon
1 Replies

2. Shell Programming and Scripting

Compare files in a folder based on another file

I have a file named file.txt that looks as follows //class1.txt 45 234 67 89 90 //class2.txt 456 34 78 89 120 class1 and class2.txt are the names of files in a folder named folder1. The content of class1.txt file in folder1 67 9 89 5 234 9The content of class2.txt file in... (1 Reply)
Discussion started by: jaff rufus
1 Replies

3. Shell Programming and Scripting

Compare three files based on two fields

Guys, I tried searching on the internet and I couldn't get the answer for this problem. I have 3 files. First 2 fields of all of them are of same type, say they come from various databases but first two fields in the 3 files means the same. I need to verify the entries that are not present... (4 Replies)
Discussion started by: PikK45
4 Replies

4. Shell Programming and Scripting

Compare two files, then outputs line number

I have two files, "ranked.txt" and "sorted.txt". Sorted.txt is a smaller subset from ranked.txt that is sorted in alpha order. However ranked.txt preserves the ranking of words I would like to keep. How do I check the rank of every word in sorted.txt when matched to the original ranked.txt? I... (8 Replies)
Discussion started by: pxalpine
8 Replies

5. Shell Programming and Scripting

compare 2 files based on columns

Hi Experts, Is there a way to compare 2 files by columns and print matching cases. I have 2 files as below, I want cases where col1 and col2 in f1 matches col1 and col2 in f2 to be printed as output. The separator is space. I want the output to have col1 col2 col 3 from both files printed... (7 Replies)
Discussion started by: novice_man
7 Replies

6. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

7. Shell Programming and Scripting

Compare two files based on values of fields.

Hi All, I have two files and data looks like this: File1 Contents #Field1,Field2 Dist_Center_file1.txt;21 Dist_Center_file3.txt;20 Dist_Center_file2.txt;20 File2 Contents (*** No Header ***) Dist_Center_file1.txt;23 Dist_Center_file2.txt;20 Dist_Center_file3.txt;20 I have... (4 Replies)
Discussion started by: Hangman2
4 Replies

8. Shell Programming and Scripting

Compare two files based on integer part only

Please see how can I do this: File A (three columns): X1,Y1,1.01 X2,Y2,2.02 X3,Y3,4.03 File B (three columns): X1,Y1,1 X2,Y2,2 X3,Y3,4.0005 Now I have to compare file A and B based on the integer part of column 3. Means first 2 rows should be OK and the third row should not satisfy... (12 Replies)
Discussion started by: yale_work
12 Replies

9. Shell Programming and Scripting

How to compare 2 files & get only few columns based on a condition related to both files?

Hiiiii friends I have 2 files which contains huge data & few lines of it are as shown below File1: b.dat(which has 21 columns) SSR 1976 8 12 13 10 44.00 39.0700 70.7800 7.0 0 0.00 0 2.78 0.00 0.00 0 0.00 2.78 0 NULL ISC 1976 8 12 22 32 37.39 36.2942 70.7338... (6 Replies)
Discussion started by: reva
6 Replies

10. Shell Programming and Scripting

compare 2 outputs

Hello, I have a shell script that is used as follows: ./script -s <Oracle_server_name> the script returns several lines in this format: parameter name required value Current Value comments --------------- ------------- -------------- --------- My objective now is to compare 2... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies
Login or Register to Ask a Question