sort out the required data


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users sort out the required data
# 1  
Old 04-20-2009
sort out the required data

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.
# 2  
Old 04-20-2009
Try this:

Code:
sed 's!\(.*\)|\(.*\)|\(.*\)|!s/\2//g!'  file2 >temp_file
sed -f temp_file file1

# 3  
Old 04-20-2009
Code:
awk -F"|" 'FNR==NR && $(NF-1) == "27"{active[$1]=$2; next}
{
 old=$0
 gsub(/Name: |\.net.*/,"")
 gsub(active[$0],"",old)
 print old  
}' file2 file1

# 4  
Old 04-20-2009
MySQL

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.
# 5  
Old 04-20-2009
Quote:
Originally Posted by imas
This code works as per my requirement.
sed 's!\(.*\)|\(.*\)|\(.*\)|!s/\2//g!' file2 >temp_file
sed -f temp_file file1
Hmmm... I guess that code gives unexpected results if your files are like the following:
Code:
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

Code:
000f9fbc6738|10.84.2.222|27|
001371e8ed3e|10.84.1.101|27|
00e06f5bd42a|10.72.19.218|27|

# 6  
Old 04-24-2009
Yes sir,

Good catch, however how to get rid of this issue.


Thanks
-imas
# 7  
Old 04-24-2009
Quote:
Originally Posted by imas
Good catch, however how to get rid of this issue.
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetching the required data out of a tabular form

Hello Gurus, I am trying to fetch a required number of lines from an output of a command which is in tabular form. Below is the command for reference along with how the result is being shown on UNIX shell. /usr/openv/volmgr/bin/vmquery -b -p 5 The result of the above command is as... (6 Replies)
Discussion started by: Ali Sarwar
6 Replies

2. Shell Programming and Scripting

How to Modify a file content in UNIX and sort for only required fields ?

I have the below contents in a file after making the below curl call curl ... | grep -E "state|Rno" | paste -sd',\n' | grep "Disconnected" > test "state" : "Disconnected",, "Rno" : "5554f1d2" "state" : "Disconnected",, "Rno" : "10587563" "state" : "Disconnected",, "Rno" :... (2 Replies)
Discussion started by: Vaibhav H
2 Replies

3. Shell Programming and Scripting

Help Need to fetch the required data

Hi Guys, Am in need of your help one more time on my real data. I have a file which contains more than thousand lines of data Live data shown for 4 iterations. We have more than thousand lines of data:- -------------------------------------------------------------------------- ... (4 Replies)
Discussion started by: rocky2013
4 Replies

4. Shell Programming and Scripting

Need to cut a some required data from file

Data_Consolidation_Engine_Part_2_Job2..TgtArBkt: ORA-00942: table or view does not exist I have some thing like above in the file.. Upto this portion Data_Consolidation_Engine_Part_2_Job2..TgtArBkt: the length can be vary .. Can some one help me in taking this portion alone ORA-00942:... (7 Replies)
Discussion started by: saj
7 Replies

5. UNIX for Advanced & Expert Users

Alternative to sort -ur +1 required

I've got scripts trawling the network and dumping parsed text into files with an Epoch timestamp in column 1. I append the old data to the new data then just want to keep the top entry if there is an identical duplicate below (column 1 needs to be ignored). sort -ur +1 works a treat on a Solaris... (16 Replies)
Discussion started by: Mike Smith
16 Replies

6. Shell Programming and Scripting

Want to sort a file using awk & sed to get required output

Hi All, Need Suggestion, Want to sort a file using awk & sed to get required, output as below, such that each LUN shows correct WWPN and FA port Numbers correctly: Required output: 01FB 10000000c97843a2 8C 0 01FB 10000000c96fb279 9C 0 22AF 10000000c97843a2 8C 0 22AF 10000000c975adbd ... (10 Replies)
Discussion started by: aix_admin_007
10 Replies

7. Shell Programming and Scripting

Perl script required for processing the data

I have following result.log file (always has 2 lines) which I need to process, cat result.log name.cmd.method,"result","abc","xyz"; name="hello,mine.12345,"&"tree"&" xyz "&" tree "&" xyz", data="way,"&" 1"&"rate-me"&"1"&"rate-me",str="",ret=""; now I need to extract the strings/data as... (4 Replies)
Discussion started by: perlDiva
4 Replies

8. Shell Programming and Scripting

[Solved] Messaging data into required report

Hello to all; hope someone can assist me in getting the required output that my manager is expecting. I have been able to generate this code which does the comparison of the files and creates the file called diff_fuss_file.txt $ vi fussrpt.pl #!/usr/bin/perl #cd /tmp #rm output.txt ... (2 Replies)
Discussion started by: gvolpini
2 Replies

9. UNIX and Linux Applications

Get the data in my required form using gawk

i had the data in the following form: Branch : 3379 As On : 31-JAN-2009 Page : 1 User Id : OPER1 Date & Time : 01-FEB-2009 04:02:37 ... (2 Replies)
Discussion started by: KANNI786
2 Replies

10. Shell Programming and Scripting

grep required data from two columns

hello, I have output from a command and I need to filter some info out of that. I tried awk command but I can not grep what I am looking for: Following is the output and I need to capture "disabled" for each volume from first column and report: # vol status Volume State ... (2 Replies)
Discussion started by: za_7565
2 Replies
Login or Register to Ask a Question