Visit The New, Modern Unix Linux Community


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
# 1  
Trying to use diff output to compare to a separate file

I have two files:
Code:
smw:/working/iso_testing # cat a
QConvergeConsoleCLI-1.1.03-49.x86_64.rpm
aaa_base-13.2+git20140911.61c1681-1.3.i586.rpm
acpica-20140724-2.1.2.i586.rpm
test.rpm

Code:
smw:/working/iso_testing # cat b
QConvergeConsoleCLI-1.1.03-49.x86_64.rpm
aaa_base-13.2+git20140911.61c1681-1.3.i586.rpm
acpica-20140724-2.1.2.i586.rpm


--If I diff them I see this:
Code:
smw:/working/iso_testing # diff a b
4d3
< test.rpm

I want to take THAT output (test.rpm) and grep it out of a third file. A.K.A. file c:

Code:
smw:/working/iso_testing # cat c
QConvergeConsoleCLI QConvergeConsoleCLI-1.1.03-49.x86_64.rpm
aaa_base aaa_base-13.2+git20140911.61c1681-1.3.i586.rpm
acpica acpica-20140724-2.1.2.i586.rpm
test test.rpm

My desired output would look something like
Code:
test test.rpm

Perhaps I have to many files to begin with but I'm stuck.
Thanks in advance

File A is the list or rpm's from one repo, file B is a list of rpm's from a .csv file, and file C is a copy of file B but with package names, not just the rpm.***
# 2  
try awk - do a difference for a b in awk, remember it, find it c
Order file names parameters you give to awk is important: should be b then a then c where a is the file with the difference, c is the file to do a lookup,
will find many different records not in file b searching file c.
Code:
awk '
       FILENAME=="a" {arr[$0]++; next}
       FILENAME=="b" {if( !arr[[$0] ) {srch[$0]++}
       FILENAME=="c" {if(srch[$0]) {print FILENAME, $0}
      '  b a c

This User Gave Thanks to jim mcnamara For This Post:
# 3  
I'm pretty new to this, but am I doing something wrong?

Code:
smw:/working/iso_testing # awk '
>        FILENAME=="a" {arr[$0]++; next}
>        FILENAME=="b" {if( !arr[[$0] ) {srch[$0]++}
>        FILENAME=="c" {if(srch[$0]) {print FILENAME, $0}
>       '  b a c
awk: cmd. line:3:        FILENAME=="b" {if( !arr[[$0] ) {srch[$0]++}
awk: cmd. line:3:                                ^ syntax error
awk: cmd. line:4:        FILENAME=="c" {if(srch[$0]) {print FILENAME, $0}
awk: cmd. line:4:                      ^ syntax error
awk: cmd. line:5:
awk: cmd. line:5:       ^ unexpected newline or end of string

# 4  
just a wild guess -extra [ for file the b case:
Code:
awk '
       FILENAME=="a" {arr[$0]++; next}
       FILENAME=="b" {if( !arr[$0] ) {srch[$0]++}
       FILENAME=="c" {if(srch[$0]) {print FILENAME, $0}
      '  b a c

if on Solaris, use nawk instead of awk.
This User Gave Thanks to vgersh99 For This Post:
# 5  
This for bash on SLES 12.

Code:
smw:/working/iso_testing # awk '
>        FILENAME=="a" {arr[$0]++; next}
>        FILENAME=="b" {if( !arr[$0] ) {srch[$0]++}
>        FILENAME=="c" {if(srch[$0]) {print FILENAME, $0}
>       '  b a c
awk: cmd. line:4:        FILENAME=="c" {if(srch[$0]) {print FILENAME, $0}
awk: cmd. line:4:                      ^ syntax error
awk: cmd. line:5:
awk: cmd. line:5:       ^ unexpected newline or end of string

# 6  
ok, we're getting there...
Code:
awk '
       FILENAME=="a" {arr[$0]++; next}
       FILENAME=="b" {if( !arr[$0] ) srch[$0]++}
       FILENAME=="c" {if(srch[$0]) print FILENAME, $0}
      '  b a c

# 7  
Hey!!!
No syntax errors Smilie
No output either.
I was hoping to see:

Code:
test test.rpm

So I'll keep playing.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #682
Difficulty: Easy
Steve Job's was the primary founder and majority shareholder of Pixar
True or False?

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

Featured Tech Videos