Data differences


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Data differences
# 1  
Old 06-30-2010
Data differences

I have the following awk command, reading data from my local server(sun5) and remote server(sun8).Each doing the same command and displaying the differences into a diffs.txt file.
Code:
 
awk 'BEGIN {while ( getline < "sun5-printers.txt") {arr[$0]++ } } { if (!($0 in a
rr ) ) { print } }' sun8-printers.txt > diffs.txt


problem is that its not picking up all differences and displaying them.
here is an example:
sun5-printers.txt file

Code:
device for 5001a10: lpd://172.25.5.124:515
device for 5001a11: lpd://172.25.5.155:515
device for 5001a55: lpd://172.25.6.31:515
device for 5001a77: lpd://172.25.12.34:515
device for 5001a88: lpd://172.25.6.86:515
device for 5001a99: lpd://172.25.6.31:515

sun8-printers.txt file
Code:
device for 5001a11: lpd://172.25.5.155:515
device for 5001a44: lpd://172.25.6.31:515
device for 5001a77: lpd://172.25.12.34:515
device for 5001a88: lpd://172.25.6.86:515
device for 5001a99: lpd://172.25.6.31:515

NOTICE that its not picking up the 5001a55. Any advice on how to fix the awk command?????
Smilie
diffs.txt file
Code:
device for 0601ps1: lpd://172.25.53.36:515
device for 0601ps2: lpd://172.25.53.30:515
device for 0606ge1: lpd://172.28.9.29:515
device for 5001a44: lpd://172.25.6.31:515

# 2  
Old 06-30-2010
Hi

your script is to print those lines in sun8-printers.txt which is not there in sun5-printers.txt, and hence the line which you expected did not come out since its not there in sun8-printers.txt.

What is your expected functionality?

Guru.
# 3  
Old 06-30-2010
The expected functionality is too display, differences in both the remote server and the local server.
oh okay, how can i change the awk command , so that it will display differences in the sun5-printers.txt as well as sun8-printers.txt?

---------- Post updated at 12:22 ---------- Previous update was at 10:19 ----------

Would reversing the filenames..give me a different output?????
# 4  
Old 06-30-2010
You can try this:
Code:
awk 'NR==FNR{arr[$0]=$0; next}
$0 in arr {delete arr[$0]; next} {print}
END{for( i in arr ){print arr[i]}}
' sun5-printers.txt sun8-printers.txt > diffs.txt

# 5  
Old 07-01-2010
ok ran command and now i see the differences!
thanks a million
Code:
device for 0601dn1: lpd://172.25.53.32:515
device for 0601jc1: lpd://172.25.53.33:515
device for 0601la1: lpd://172.25.53.34:515
device for 0601ps1: lpd://172.25.53.36:515
device for 0601ps2: lpd://172.25.53.30:515
device for 0606ge1: lpd://172.28.9.29:515
device for 5001a44: lpd://172.25.6.31:515
device for 0601dn1: lpd://172.25.9.102:515
device for device: ///dev/null
device for 0601jc1: lpd://172.25.9.104:515
device for 0601ps1: lpd://172.25.9.105:515
device for 0601la1: lpd://172.25.9.109:515
device for 0601ps2: lpd://172.25.9.110:515
device for 5001a55: lpd://172.25.6.31:515

Why are duplicates being displayed, as i already know that they are due to the different IP addresses on the servers?

---------- Post updated 07-01-10 at 10:18 ---------- Previous update was 06-30-10 at 14:35 ----------

any one can assist with the duplicates???

---------- Post updated at 10:54 ---------- Previous update was at 10:18 ----------

Quote:
Originally Posted by Franklin52
You can try this:
Code:
awk 'NR==FNR{arr[$0]=$0; next}
$0 in arr {delete arr[$0]; next} {print}
END{for( i in arr ){print arr[i]}}
' sun5-printers.txt sun8-printers.txt > diffs.txt

this awk works but is displaying duplicates which is causing confusion with the rest of my shell script!

My shell script reads the differences from the diffs.txt file, deletes them and then recreates them.
BUT because of the duplicates its recreating them incorrectly...
any advise please????
here is the diffs.txt
Code:
sun5 # more diffs.txt
device for 0601dn1: lpd://172.25.53.32:515
device for 0601jc1: lpd://172.25.53.33:515
device for 0601la1: lpd://172.25.53.34:515
device for 0601ps1: lpd://172.25.53.36:515
device for 0601ps2: lpd://172.25.53.30:515
device for 0606ge1: lpd://172.28.9.29:515
device for 5001a44: lpd://172.25.6.31:515
device for 0601dn1: lpd://172.25.9.102:515
device for device: ///dev/null
device for 0601jc1: lpd://172.25.9.104:515
device for 0601ps1: lpd://172.25.9.105:515
device for 0601la1: lpd://172.25.9.109:515
device for 0601ps2: lpd://172.25.9.110:515
device for 5001a55: lpd://172.25.6.31:515

the correct ip"s are the top ones...please assist.
# 6  
Old 07-01-2010
I don't get it, which lines are duplicates?

Code:
device for 0601dn1: lpd://172.25.53.32:515
device for 0601jc1: lpd://172.25.53.33:515
device for 0601la1: lpd://172.25.53.34:515
device for 0601ps1: lpd://172.25.53.36:515
device for 0601ps2: lpd://172.25.53.30:515
device for 0606ge1: lpd://172.28.9.29:515
device for 5001a44: lpd://172.25.6.31:515
device for 0601dn1: lpd://172.25.9.102:515
device for device: ///dev/null
device for 0601jc1: lpd://172.25.9.104:515
device for 0601ps1: lpd://172.25.9.105:515
device for 0601la1: lpd://172.25.9.109:515
device for 0601ps2: lpd://172.25.9.110:515
device for 5001a55: lpd://172.25.6.31:515

# 7  
Old 07-01-2010
I've been doing some research for the last three hours..keep on running into a brick wall.
Can someone please tell me how I can fix the awk command not to produce the duplicates, and only show the differences????

---------- Post updated at 14:08 ---------- Previous update was at 13:57 ----------

thanks franklin52
the names of the devices are the duplicates i am talking about. these duplicate names have different IP addresses.

Code:
device for 0601jc1: lpd://172.25.53.33:515
device for 0601jc1: lpd://172.25.9.104:515

the correct Ip is the 1st line, and the 2nd one needs to be changed.
Currently the script deletes the device fine but recreates it with the 2nd line..which is incorrect!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

{} and ( ) differences

Can u tell the diff between the 1) $a and ${a} 2)] and ( ) 3)" " and ' ' , ` ` 4) 'a' , "a", please explain with simple example (1 Reply)
Discussion started by: mrbinoy
1 Replies

2. Shell Programming and Scripting

Differences between shells

What is the practical difference among the different shell like csh , ksh , bash etc.:confused::confused: Please use descriptive subjects instead of single words (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

3. Shell Programming and Scripting

Differences between 2 directories

Hi, I am trying to write a script under ksh to list all the differences between two directories. For example: # ls test1 test2 I need to compare all the files under between test1 & test2. When I do diff, it only compares the diectoires but it doesn't check inside. I did do... (3 Replies)
Discussion started by: samnyc
3 Replies

4. Shell Programming and Scripting

Differences between 2 Flat Files and process the differences

Hi Hope you are having a great weeknd !! I had a question and need your expertise for this : I have 2 files File1 & File2(of same structure) which I need to compare on some columns. I need to find the values which are there in File2 but not in File 1 and put the Differences in another file... (5 Replies)
Discussion started by: newbie_8398
5 Replies

5. Shell Programming and Scripting

Printing the differences

Dear All, I am having a file with thousands of columns. I would like to find the difference between adjacent columns (ie $i and $(i+1)) and perform the following action: if the difference is less than -10, then i need to print "-2"; if the difference is between 0 and <-9, then i need to... (2 Replies)
Discussion started by: Fredrick
2 Replies

6. Shell Programming and Scripting

Help with file differences

I have two huge files in the size of 1gb. They are produced by similar processes and the expected thing is that they should match in size and contents. I have produced both the files with the processes and they seem to be off only by few bytes. Size file name 1634502037 ... (2 Replies)
Discussion started by: dsravan
2 Replies

7. UNIX for Dummies Questions & Answers

Differences

Hi all, I am using korn shell. I want to know what is the difference between hey and echo commands. (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

8. Shell Programming and Scripting

Sort differences

I have a file that contains /home /opt /stand /var /usr /tmp /opt /home I need to print the lines that are unique so the output would be /stand /var /usr /tmp and omit any filesystems that are duplicates. I searched the forums but did not find anything, although i searched on... (3 Replies)
Discussion started by: insania
3 Replies

9. Solaris

Differences between Solaris 2.5 and 9

Hi Can anybody tell what are the great differences in Solaris 2.5 and 9? I am seeking information like differences in libraries, User Interface, Configuraion files, daemons, Packaging and archiving tools, Hardware supported etc. Please help me, as this is little urgent. Even if you can refer... (4 Replies)
Discussion started by: charlcy
4 Replies
Login or Register to Ask a Question