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.

 
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

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

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?????
:confused:
diffs.txt file

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

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.

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

You can try this:

awk 'NR==FNR{arr[$0]=$0; next}
$0 in arr {delete arr[$0]; next} {print}
END{for( i in arr ){print arr}}
' sun5-printers.txt sun8-printers.txt > diffs.txt

ok ran command and now i see the differences!
thanks a million

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

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

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.

I don't get it, which lines are duplicates?

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

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.

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!

Try this one:

awk 'NR==FNR{arr[$3]=$0; next}
$3 in arr {delete arr[$3]; next} {print}
END{for( i in arr ){print arr}}
' sun5-printers.txt sun8-printers.txt > diffs.txt

Thanks franklin52,

I tried, the AWK as you suggested, BUT
now its ignoring the duplicates, as per example i posted.

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

herewith is the output I am now receiving

more diffs.txt
device for 0606ge1: lpd://172.28.9.29:515
device for 5001a44: lpd://172.25.6.31:515
device for device: ///dev/null
device for 5001a55: lpd://172.25.6.31:515

:confused:

Can you post some lines of the 2 input files and the expected output from the given lines?

Here some lines from the text files:
this is the local server:

tail -20 sun5-printers.txt
device for 5001jnl: lpd://172.25.12.27:515
device for 5001pr1: lpd://172.25.6.28:515
device for 5001prg: lpd://172.25.6.27:515
device for 5001x01: lpd://172.25.12.160:515
device for 5001x02: lpd://172.25.12.160:515
device for 5601ge1: lpd://172.25.12.32:515
device for 6101a01: lpd://172.25.26.26:515
device for device: ///dev/null

this is the remote server

device for 5001hp1: socket://172.25.11.213:9100
device for 5001jnl: lpd://172.25.12.27:515
device for 5001pr1: lpd://172.25.6.28:515
device for 5001prg: lpd://172.25.6.27:515
device for 5001x01: lpd://172.25.12.160:515
device for 5001x02: lpd://172.25.12.160:515
device for 5601ge1: lpd://172.25.12.32:515
device for 6101a01: lpd://172.25.26.26:515

NOTE* printers exists on both servers, but sometimes Ip addresses may change on the remote server that have to be resynced onto the local server

more diffs.txt
device for 0606ge1: lpd://172.28.9.29:515
device for 5001a44: lpd://172.25.6.31:515
device for device: ///dev/null
device for 5001a55: lpd://172.25.6.31:515

This is not the difference from given output of the local and remote server above :eek:

more diffs.txt
device for 0606ge1: lpd://172.28.9.29:515
device for 5001a44: lpd://172.25.6.31:515
device for device: ///dev/null
device for 5001a55: lpd://172.25.6.31:515

Hi franklin52,
you asked for some lines from the input files??? which i posted
and after running the awk, is the differences which it gives me..is also what i posted

or am i wrong????

OK, maybe I wasn't clear enough. An example:

Output 1:

device for : AA
device for : BB
device for : CC
device for : 11
device for : DD

Output 2:

device for : AA
device for : BB
device for : 22
device for : DD
device for : CC

Output Diff:

device for : 11 < -- not in Output 2
device for : 22 < -- not in Output 1

My orginal post was that i needed the awk to show the differences between the two out files namely sun5-printers.txt and sun8-printers.txt

device for 0606ge1: lpd://172.28.9.29:515 (from sun8-printers.txt)
device for 5001a44: lpd://172.25.6.31:515 (from sun8-printers.txt) 
device for 5001a55: lpd://172.25.6.31:515 (from sun5-printers.txt)

If this is the desired ouput:

device for 0606ge1: lpd://172.28.9.29:515 (from sun8-printers.txt)
device for 5001a44: lpd://172.25.6.31:515 (from sun8-printers.txt) 
device for 5001a55: lpd://172.25.6.31:515 (from sun5-printers.txt)

from:

tail -20 sun5-printers.txt
device for 5001jnl: lpd://172.25.12.27:515
device for 5001pr1: lpd://172.25.6.28:515
device for 5001prg: lpd://172.25.6.27:515
device for 5001x01: lpd://172.25.12.160:515
device for 5001x02: lpd://172.25.12.160:515
device for 5601ge1: lpd://172.25.12.32:515
device for 6101a01: lpd://172.25.26.26:515
device for device: ///dev/null

and:

device for 5001hp1: socket://172.25.11.213:9100
device for 5001jnl: lpd://172.25.12.27:515
device for 5001pr1: lpd://172.25.6.28:515
device for 5001prg: lpd://172.25.6.27:515
device for 5001x01: lpd://172.25.12.160:515
device for 5001x02: lpd://172.25.12.160:515
device for 5601ge1: lpd://172.25.12.32:515
device for 6101a01: lpd://172.25.26.26:515

I'm not able to give you the solution.