imas
April 20, 2009, 2:19am
1
Hi All,
I have a file 1.txt which has the duplicate dns entries as shown:
Name: 000f9fbc6738.net.in|Addresses: 10.241.66.169, 10.84.2.222,212.241.66.170
Name: 001371e8ed3e.net.in|Addresses: 10.241.65.153, 10.84.1.101
Name: 00e06f5bd42a.net.in|Addresses: 10.72.19.218, 172.18.72.250
**
**
Now I have another file 2.txt which shows the current active dns IP entry as shown:
000f9fbc6738|10.84.2.222|27|
001371e8ed3e|10.84.1.101|27|
00e06f5bd42a|10.72.19.218|27|
**
**
Note: here |27| means it is an active IP with respect to that mac.
Now i would like to sort this data i.e., I want the macaddress and IP which is inactive by comparing 1.txt and 2.txt file and the final output should look like the one as shown below:
Name: 000f9fbc6738.net.in|Addresses: 10.241.66.169,212.241.66.170
Name: 001371e8ed3e.net.in|Addresses: 10.241.65.153
Name: 00e06f5bd42a.net.in|Addresses: 172.18.72.250
**
**
Your suggestion/help is greatly appreciated.
Thanks
imas.
Try this:
sed 's!\(.*\)|\(.*\)|\(.*\)|!s/\2//g!' file2 >temp_file
sed -f temp_file file1
awk -F"|" 'FNR==NR && $(NF-1) == "27"{active[$1]=$2; next}
{
old=$0
gsub(/Name: |\.net.*/,"")
gsub(active[$0],"",old)
print old
}' file2 file1
imas
April 20, 2009, 3:18am
4
Hi Dennis
Thanks a million
This code works as per my requirement.
sed 's!\(.*\)|\(.*\)|\(.*\)|!s/\2//g!' file2 >temp_file
sed -f temp_file file1
Once again thank you very much for providing an update within no time.
Appreciate all users help.
We can close this thread.
Imas.
Hmmm... I guess that code gives unexpected results if your files are like the following:
Name: 000f9fbc6738.net.in|Addresses: 10.84.1.101, 10.84.2.222,212.241.66.170
Name: 001371e8ed3e.net.in|Addresses: 10.241.65.153, 10.84.1.101
Name: 00e06f5bd42a.net.in|Addresses: 10.72.19.218, 172.18.72.250
000f9fbc6738|10.84.2.222|27|
001371e8ed3e|10.84.1.101|27|
00e06f5bd42a|10.72.19.218|27|
imas
April 24, 2009, 12:23am
6
Yes sir,
Good catch, however how to get rid of this issue.
Thanks
-imas
It starts to get too cumbersome to do with sed alone.
I would switch to awk.
Check if the code provided by ghostdog74 works as expected.