UNIX file comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX file comparison
# 1  
Old 10-05-2015
UNIX file comparison

I have two files which has component name and version number separated by a space

Code:
cat file1 
com.acc.invm:FNS_PROD 94.0.5 
com.acc.invm:FNS_TEST_DCCC_Mangment 94.1.6 
com.acc.invm:FNS_APIPlat_BDMap 100.0.9 
com.acc.invm:SendEmail 29.6.113 
com.acc.invm:SendSms 12.23.65 

cat file2 
com.acc.invm:FNS_PROD 94.0.5 
com.acc.invm:FNS_TEST_DCCC_Mangment 94.0.6 
com.acc.invm:FNS_APIPlat_BDMap 100.0.10

needed output is:
  1. all components from file1 with a higher version than in file2
  2. all components in file1 which are not in file2.
In this example the desired output is
Code:
com.acc.invm:FNS_TEST_DCCC_Mangment 94.1.6
com.acc.invm:SendEmail 29.6.113 
com.acc.invm:SendSms 12.23.65

The first line appears because file1 has a higher version (rule 1), the other lines appear because these components do not appear in file2 (rule 2). The FNS_PROD line does not appear because the version numbers are the same. FNS_APIPlat_BDMap doesn't appear because it is a higher version in file2.
tried awk but output is not as desired output.


Code:
join -a1 file1 file2 | awk '$2 > $3 {print $1,$2}'

Please help.
# 2  
Old 10-05-2015
Hello again

Deja-vu: File compare in UNIX
So the question remains, after several suggestions, any attemps from your side yet?

Thank you
# 3  
Old 10-05-2015
I tried to write awk code but its not giving the o/p which is required.


Code:
cat tst.awk 
{ split($2,a,/\./); curr = a[1]*10000 + a[2]*100 + a[3] } 
NR==FNR { prev[$1] = curr; next } 
!($1 in prev) || (curr > prev[$1]) 

 $ /usr/bin/nawk -f tst.awk file2 file1

# 4  
Old 10-05-2015
Maybe this could get you started:
Code:
FILE1=file1
FILE2=file2
while IFS=":" read _ DESC VER
do
	ver=$(awk -v DESC="$DESC" '/DESC/ {print $2}' $FILE2|sed s,"\[|\]",,)
	printf '%s\n' \
		"Version number handling here:" \
		"$DESC: $VER (f1) ~= $ver (f2)"
done<$FILE1

hth
This User Gave Thanks to sea For This Post:
# 5  
Old 10-05-2015
Did you try anything to debug "your" awk code?
This User Gave Thanks to RudiC For This Post:
# 6  
Old 10-08-2015
My awk code working Smilie Smilie
# 7  
Old 10-08-2015
Why don't you post your solution so others can benefit from it?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help regarding comparison between two files through UNIX script

Hi All , I am aware of unix command ,but not comforable in putting together in script level.I came to situation where I need to compare between two .txt files fieldwise and need a mismatch report. As I am new to unix script arena ,if anyone can help in the below scenario that will be really... (9 Replies)
Discussion started by: STCET22
9 Replies

2. Shell Programming and Scripting

Comparison between two files through UNIX script

Hi All , As I am new to unix scripting ,I need a help regarding unix scripting .I have two .txt files .One is source file and another is target file.I need a script through which I can compare those two files.I need a automated comparison report in a directory after comparing between source &... (2 Replies)
Discussion started by: STCET22
2 Replies

3. Shell Programming and Scripting

File comparison in UNIX columnwise

Hi all, I want to compare two files with same number of rows and columns with records in same order. Just want to highlight the differences in the column values if any. file A 1,kolkata,19,ab 2,delhi,89,cd 3,bangalore,56,ef file2: 1,kolkata,21,ab 2,mumbai,89,gh 3,bangalore,11,kl... (9 Replies)
Discussion started by: prabhat.diwaker
9 Replies

4. Shell Programming and Scripting

comparison of 2 files using unix or awk

Hello, I have 2 files and I want them to be compared in a specific fashion file1: A_1200_1250 A_1251_1300 B_1301_1350 B_1351_1400 B_1401_1450 C_1451_1500 and so on... file2: 1210 1305 1260 1295 1400 1500 1450 1495 Now The script should look for "1200" from A_1200_1250 of... (8 Replies)
Discussion started by: Diya123
8 Replies

5. UNIX for Dummies Questions & Answers

A comparison of the multi-user facilities in Unix and Microsoft Windows.

hi guys just give me some information about multi user facilities that unix offer in cmparison to windows. Thanx (2 Replies)
Discussion started by: nadman123
2 Replies

6. UNIX for Dummies Questions & Answers

Comparison Unix and Windows file sysytem

i want to know the similarities and disimilarities of Unix and Windows file systems . methods of file , file orgsnization , meaning of file extension , file and disk fragments :confused::confused: (1 Reply)
Discussion started by: localp
1 Replies

7. Shell Programming and Scripting

comparison of strings in unix shell scripting

Hi STORAGE_TYPE=$1 echo "########### SQL SESSION STARTED ###########" VALUE=`sqlplus -S /nolog << THEEND connect tcupro/tcupro_dev@bdd1optn SET SERVEROUTPUT ON DECLARE V_STORAGE_TYPE varchar2(3); V_ERR_MSG varchar2(255) ; V_LOG_LEVEL varchar2(200); BEGIN... (1 Reply)
Discussion started by: piscean_n
1 Replies

8. UNIX for Dummies Questions & Answers

Comparison of 2 files in UNIX

Hi, There are two files in UNIX system with some lines are exactly the same, some lines are not. I want to compare these two files.The 2 files (both the files have data in Column format )should be compared row wise and any difference in data for a particular row should lead to storage of data of... (32 Replies)
Discussion started by: Dana Evans
32 Replies

9. UNIX for Dummies Questions & Answers

Unix comparison

I am very new to Unix. What are the similiarities and differences between ScoUnix and AIX5 if any? Where might i find the information? Which is better? (1 Reply)
Discussion started by: NewGuy100
1 Replies

10. Programming

Unix Programming Book Comparison

Hi, I am starting out to program on Unix, having had experience in C and C++ in DOS. I would like to know, of these three, which is the best book for learning C programming in Unix: Advanced Unix Programming by Marc Rochkind Advanced Unix Programming by Warren Gay Advanced Programming in... (6 Replies)
Discussion started by: theicarusagenda
6 Replies
Login or Register to Ask a Question