Trying to use diff output to compare to a separate file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to use diff output to compare to a separate file
# 8  
Old 10-18-2017
Unfortunately, there's a small logical flaw in above; the sequence of files and thus how the arrays are populated DOES matter. Try
Code:
awk '
       FILENAME=="b" {arr[$0]++; next}
       FILENAME=="a" {if( !arr[$0] ) srch[$0]++}
       FILENAME=="c" {if(srch[$2]) print}
      '  b a c
test test.rpm


EDIT: How about
Code:
grep $(diff -y -b --suppress-common-lines a b | cut -f1) c
test test.rpm

This User Gave Thanks to RudiC For This Post:
# 9  
Old 10-18-2017
This User Gave Thanks to drl For This Post:
# 10  
Old 10-18-2017
Thanks RudiC, your awk statement worked perfectly and I was able to test it out on some different scenarios.

I tried the same grep command you did, but got a little stuck when the output wasn't what I liked..

Code:
smw:/working/iso_testing # grep $(diff -y -b --suppress-common-lines a b | cut -f1) c
grep: zip.rpm: No such file or directory
c:test test.rpm

P.S. I added the zip zip.rpm to my FILE C and zip.rpm to file A.

Thank you much!!!!
# 11  
Old 10-18-2017
That sounds like an unexpected result of the diff "command substitution", which in turn might be due to non-compliant input files' contents.
Please post the result of the diff alone / on its own.
# 12  
Old 10-18-2017
Code:
smw:/working/iso_testing # diff -y -b --suppress-common-lines a b | cut -f1
test.rpm
zip.rpm
smw:/working/iso_testing #
smw:/working/iso_testing # grep $(diff -y -b --suppress-common-lines a b | cut -f1) c
grep: zip.rpm: No such file or directory
c:test test.rpm


Last edited by Don Cragun; 10-18-2017 at 03:53 PM.. Reason: Fix CODE tags.
# 13  
Old 10-19-2017
Ah - sorry, my fault. Try enclosing the "command substitution" in double quotes and report back.
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 string in two separate file and delete some line of file

Hi all i want to write program with shell script that able compare two file content and if one of lines of file have # at the first of string or nothing find same string in one of two file . remove the line in second file that have not the string in first file. for example: file... (2 Replies)
Discussion started by: saleh67
2 Replies

2. Shell Programming and Scripting

Compare large file and identify difference in separate file

I have a very large system generated file containing around 500K rows size 100MB like following HOME|ALICE STREET|3||NEW LISTING HOME|NEWPORT STREET|1||NEW LISTING HOME|KING STREET|5||NEW LISTING HOME|WINSOME AVENUE|4||MODIFICATION CAR|TOYOTA|4||NEW LISTING CAR|FORD|4||NEW... (9 Replies)
Discussion started by: jubaier
9 Replies

3. Shell Programming and Scripting

compare 2 CSV fields from same diff output

Attached is a file called diff.txt It is the output from this command: diff -y --suppress-common-lines --width=5000 1.txt 2.txt > diff.txt I have also attached 1.txt and 2.txt for your convenience. Both 1.txt and 2.txt contain one very long CSV string. File 1.txt is a CSV dump of... (0 Replies)
Discussion started by: gvolpini
0 Replies

4. Shell Programming and Scripting

using diff to on two file but ignoring the last comma separate value

Hi guys I have two file which I sdiff. ie file 1: AA,12,34,56,,789,101,,6666 file 2: AA,12,34,56,,789,101,,7777 The last comma separated value will always change from one day to the next. Is there another unix utility I can use that will sdiff two files but ignore the last comma... (1 Reply)
Discussion started by: wny201
1 Replies

5. Shell Programming and Scripting

awk to compare diff output by fields

Diff output as follows: < AAA BBB CCC DDD EEE 123 > PPP QQQ RRR SSS TTT 111 > VVV WWW XXX YYY ZZZ 333 > AAA BBB CCC DDD EEE 124 How can i use awk to compare the last field to determine if the counter has increased, and need to ensure that the first 4 fields must have the same... (15 Replies)
Discussion started by: ux4me
15 Replies

6. Shell Programming and Scripting

Compare file timestamp with current date. Diff must be 1 hour.

Hello, I've created the script below to compare the content of two files with a delay of an hour. After an hour, the lines that exist in both files, will be printed and executed. The script now uses a counter to countdown 50 minutes. But what I would prefer is to check the file timestamp of... (3 Replies)
Discussion started by: taipan
3 Replies

7. Shell Programming and Scripting

Compare two files and output diff to third file

I have made several attempts to read two files of ip addresses and eliminate records from file1 that are in file2. My latest attempt follows. Everything works except my file3 is exactly the same as file1 and it should not be. # !/usr/bin/bash # # NoInterfaces # Utility will create a file... (8 Replies)
Discussion started by: altamaha
8 Replies

8. UNIX for Advanced & Expert Users

File Compare and Create New File with Diff

I need to compare File A with File B and create FILE C with the difference record only. What I mean is File A has 3 records and File B has 4 records, so FILE C will only have 1 record (becuase that record is in FILE B and not in File A). Hope I am making sense. The data layout is that each data... (7 Replies)
Discussion started by: guiguy
7 Replies

9. Shell Programming and Scripting

compare two .dat files and if there is any difference pulled into a separate file

Hi, compare two .dat files and difference will be moved into separate file.if anybody having code for this please send asap. using diff command, i don't know how to write shell programming. and my first file is like this including Header and trailer 10Ç20060323Ç01(Header) 01ÇIÇbabuÇ3000 01ÇIÇbaluÇ4000... (1 Reply)
Discussion started by: kirankumar
1 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question