[diff] hide missing rows, show similar


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [diff] hide missing rows, show similar
# 1  
Old 02-16-2012
[diff] hide missing rows, show similar

Hi all!
Having the following two csv files:

file1
Code:
AAA;0000;RED
CCC;9900;GREEN

file2
Code:
AAA;0000;BLACK
BBB;0099;BLU

What's the correct syntax to hide only the missing rows (BBB,CCC) and show the rows that differ only with last field?

I expect something like this:
Code:
diff <options> file1 file2
< AAA;0000;RED
> AAA;0000;BLACK

Also, is it possible to show an output like this directly with diff?
Code:
AAA;0000;RED;BLACK

Thank you very much!
Evan
# 2  
Old 02-16-2012
diff, as its name implies, shows differing lines.

If you want lines in common, there's a different utility for that, comm. It outputs three columns, lines unique to file1, lines unique to file2, and lines common to both. You can suppress any of these, so:

Code:
comm -1 -2 file1 file2

should print only lines that appear in both.
# 3  
Old 02-16-2012
Code:
comm -12 file1 file2

will print lines that appear in both

Code:
comm -13 file1 file2

will print lines that appear only in file2

Code:
comm -23 file1 file2

will print lines that appear only in file1

Code:
comm -3 file1 file2

will write on the left lines that appear only in file1 and on the right lines that appear only in file2
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To group the text (rows) by similar columns-names in a file

As part of some report generation, I've written a script to fetch the values from DB. But, unluckily, for certain Time ranges(1-9.99,10-19.99 etc), I don't have data in DB. In such cases, I would like to write zero (0) instead of empty. The desired output will be exported to csv file. ... (1 Reply)
Discussion started by: kumar_karpuram
1 Replies

2. Shell Programming and Scripting

Transposing rows to columns with multiple similar lines

Hi, I am trying to transpose rows to columns for thousands of records. The problem is there are records that have the same lines that need to be separated. the input file as below:- ID 1A02_HUMAN AC P01892; O19619; P06338; P10313; P30444; P30445; P30446; P30514; AC Q29680; Q29837;... (2 Replies)
Discussion started by: redse171
2 Replies

3. Shell Programming and Scripting

awk to find the avg of every 3 rows but only show last result?

Hi, I've got as far as this: awk '{sum+=$1}(NR%3==1){avg=sum/3; print avg}' input.txt Input it: 0.1 txt txt 0.2 txt txt 0.3 txt txt So, the I get the results: 0.0333333 0.133333 0.2 (8 Replies)
Discussion started by: JohnnyEnglish
8 Replies

4. Shell Programming and Scripting

Need help in splitting the string to diff rows

Hi, I have file with values as below 1~ab~456~ac:bd:de:ef~yyyy-mm-dd 2~cd~458~af:fg:ty:er:ty:uj:io:~yyyy-mm-dd I want the o/p as for frist row 1~ab~456~ac~yyyy-mm-dd 1~ab~456~bd~yyyy-mm-dd 1~ab~456~de~yyyy-mm-dd 1~ab~456~ef~yyyy-mm-dd and for the second row 2~cd~458~af~yyyy-mm-dd... (4 Replies)
Discussion started by: rithushri
4 Replies

5. Shell Programming and Scripting

How to make diff show differences one line at a time and not group them?

Is there a way to tell diff to show differences one line at a time and not to group them? For example, I have two files: file1: line 1 line 2 line 3 diff line 4 diff line 5 diff line 6 line 7 file2: line 1 line 2 line 3 diff. line 4 diff. line 5 diff. line 6 line 7 (13 Replies)
Discussion started by: mmr11408
13 Replies

6. Shell Programming and Scripting

Join txt files with diff cols and rows

I am a new user of Unix/Linux, so this question might be a bit simple! I am trying to join two (very large) files that both have different # of cols and rows in each file. I want to keep 'all' rows and 'all' cols from both files in the joint file, and the primary key variables are in the rows.... (1 Reply)
Discussion started by: BNasir
1 Replies

7. Shell Programming and Scripting

Show the diff in two files using awk

Hi, How can i use AWK or any other commands to find the difference between 2 files. File A aaa bbb ccc 111 222 File B aaa ccc 111 Output bbb 222 (6 Replies)
Discussion started by: gambit97
6 Replies

8. Shell Programming and Scripting

Show entire lines with diff command

Hi, When I run the diff command using diff -yt file1 file2, I get the output in which original lines are truncated. I tried using -W switch with diff. However, that does not produce exact output as I want. Is it possible to show entire line of file1 and file2 in diff command's output? ... (8 Replies)
Discussion started by: jal_capri
8 Replies

9. Shell Programming and Scripting

merge similar rows

I have a large file (10M lines) that contains two columns: a frequency and a string, ex: 3 aaaaa 4 bbbbb 2 ccccc 5 aaaaa 1 ddddd 4 ccccc I need to merge the lines whose string part is the same, while updating the frequency. The output should look like this: 8 aaaaa 4 bbbbb 5 ccccc... (2 Replies)
Discussion started by: tootles564
2 Replies

10. UNIX for Dummies Questions & Answers

match similar rows. uniq?

hi i have data which is in two columns (such as below). i need to compare two rows against each other and if one row matches the other row (except for different case), and their values in the second column are different, then it prints out one of the rows (either is fine). here is an... (5 Replies)
Discussion started by: Streetrcr
5 Replies
Login or Register to Ask a Question