Show the diff in two files using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Show the diff in two files using awk
# 1  
Old 04-13-2011
MySQL 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
Code:
aaa
bbb
ccc
111
222

File B
Code:
aaa
ccc
111

Output
Code:
bbb
222

Will it work for csv file too?

Thank you.

Last edited by Franklin52; 04-13-2011 at 08:34 AM.. Reason: Please use code tags
# 2  
Old 04-13-2011
If you are using bash:
Code:
comm -23 <(sort file_a) <(sort file_b)

# 3  
Old 04-13-2011
can't compare line by line
as file Bis a subset of file A
all the content in file B can be file A.
So I want to see what are the lines in file A that is not in file B.

Thanks

---------- Post updated at 07:04 PM ---------- Previous update was at 06:49 PM ----------

sorry if the files are like this:
File A
Code:
abcd, 12334
bbb, 333
ccc, 555
ddd, 555

File B
Code:
abcd
ccc
ddd

Output
Code:
bbb


Thanks

Last edited by Franklin52; 04-13-2011 at 08:34 AM.. Reason: Please use code tags
# 4  
Old 04-13-2011
Try:
Code:
comm -23 <(cut -d"," -f1 file_a|sort) <(sort file_b)

# 5  
Old 04-13-2011
Hi we have two commands in unix to find the differende.
  1. cmp file1 file2
  2. diff file1 file2
try these..
# 6  
Old 04-13-2011
Code:
awk -F, '{a[$1]++} END{for(row in a) if(a[row]==1) print row}' file*

This User Gave Thanks to kato For This Post:
# 7  
Old 04-14-2011
thanks alot..
Smilieit seemed to work
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diff 3 files, but diff only their 2nd column

Guys i have 3 files, but i want to compare and diff only the 2nd column path=`/home/whois/doms` for i in `cat domain.tx` do whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

2. Shell Programming and Scripting

Awk: Replacement using 2 diff files input and comparison

Requirement: If $5(date field) in ipfile is less than $7(date field) in deact file & $1 of ipfile is present in deactfile then $1 to be replaced by $2,$3,$4,$5,$6 of deact file else if $5(date field) in ipfile is greater than $7(date field) in actfile & $1 of ipfile is present in actfile then... (5 Replies)
Discussion started by: siramitsharma
5 Replies

3. Shell Programming and Scripting

awk - show field separator

I am using this code to insert something into a csv file: awk -F";" -v url=$url -v nr=$nr 'NR==nr{$2=url$2}1' file Why do I get the output field1 field2 instead of field1;field2 I have given -F";", so the field separator should surely be ";". (1 Reply)
Discussion started by: locoroco
1 Replies

4. UNIX for Dummies Questions & Answers

[diff] hide missing rows, show similar

Hi all! Having the following two csv files: file1 AAA;0000;RED CCC;9900;GREEN file2 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: diff <options> file1... (2 Replies)
Discussion started by: Evan
2 Replies

5. UNIX for Dummies Questions & Answers

diff then awk two files

Hi friends, i am trying to diff two files and the result will be passed to awk and this will get the first 20 characters in every line and put the result in a file.... but i can't generate an output. $ cat file1.txt 1 2 3 4 5 $ cat file2.txt 1 2 3 4 the line of command is: (2 Replies)
Discussion started by: kokoro
2 Replies

6. 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

7. 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

8. Shell Programming and Scripting

Diff between 2 files using awk

Hi Experts, Could you please help me to find the difference between two files. I tried the diff command but did not like the output as it contained < and > signs and the line numbers. Is it possible to do something using awk? I have two files, say File1.txt contains 5 values and File2.txt... (6 Replies)
Discussion started by: forumthreads
6 Replies

9. Shell Programming and Scripting

Find duplicates from multuple files with 2 diff types of files

I need to compare 2 diff type of files and find out the duplicate after comparing each types of files: Type 1 file name is like: file1.abc (the extension abc could any 3 characters but I can narrow it down or hardcode for 10/15 combinations). The other file is file1.bcd01abc (the extension... (2 Replies)
Discussion started by: ricky007
2 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