Diff 3 files, but diff only their 2nd column


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Diff 3 files, but diff only their 2nd column

Guys i have 3 files,
but i want to compare and diff only the 2nd column


Code:
path=`/home/whois/doms`
for i in `cat domain.tx`
do
whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant
whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin
whois $i| sed -n '/Registry Tech ID:/,/Tech Email:/p' > $path/$i.tech
done


Code:
File1.
Registry Registrant ID:
Registrant Name: Dns Admin
Registrant Organization: Google Inc.
Registrant Street: Please contact contact-admin@google.com, 1600 Amphitheatre Parkway
Registrant City: Mountain View
Registrant State/Province: CA
Registrant Postal Code: 94043
Registrant Country: US
Registrant Phone: +1.6502530000
Registrant Phone Ext:
Registrant Fax: +1.6506188571
Registrant Fax Ext:
Registrant Email: dns-admin@google.com



File2
Registry Admin ID:
Admin Name: DNS Admin
Admin Organization: Google Inc.
Admin Street: 1600 Amphitheatre Parkway
Admin City: Mountain View
Admin State/Province: CA
Admin Postal Code: 94043
Admin Country: US
Admin Phone: +1.6506234000
Admin Phone Ext:
Admin Fax: +1.6506188571
Admin Fax Ext:
Admin Email: dns-admin@google.com


File 3
Registry Tech ID:
Tech Name: DNS Admin
Tech Organization: Google Inc.
Tech Street: 2400 E. Bayshore Pkwy
Tech City: Mountain View
Tech State/Province: CA
Tech Postal Code: 94043
Tech Country: US
Tech Phone: +1.6503300100
Tech Phone Ext:
Tech Fax: +1.6506181499
Tech Fax Ext:
Tech Email: dns-admin@google.com

im hoping it will print the line the difference. if all is the same. jsut print all the data in file2
# 2  
As much as I'd like to help, I can't, same as I couldn't with your last, almost identical request. How should lines be compared? Based on line No.? On item (city? phone?)? What should the output look like? What if file2's entry is identical to file1's but different to file3's?
Please be way more specific!
What have you tried so far?

---------- Post updated at 19:39 ---------- Previous update was at 19:23 ----------

Not sure if this will meet your desired result:
Code:
awk     '               {n=split ($1, T, " "); sub (T[1] " ", "", $1)}
         FNR==NR        {C[$1]=$0; next}
         $1 in C        {X=C[$1]; m=split (X, TMP); if (TMP[m] != $2) C[$1]= X ":" $2}
         END            {for (c in C) print C[c]}
        ' FS=":" OFS=":" file2 file1 file3
Email: dns-admin@google.com
Street: 1600 Amphitheatre Parkway: Please contact contact-admin@google.com, 1600 Amphitheatre Parkway: 2400 E. Bayshore Pkwy
Admin ID:
Postal Code: 94043
City: Mountain View
Country: US
Name: DNS Admin: Dns Admin: DNS Admin
State/Province: CA
Organization: Google Inc.
Fax: +1.6506188571: +1.6506181499
Fax Ext:
Phone: +1.6506234000: +1.6502530000: +1.6503300100
Phone Ext:

But: this is based on some assumptions and it is not too robust...

Last edited by RudiC; 03-13-2015 at 07:20 PM..
This User Gave Thanks to RudiC For This Post:
# 3  
Thanks Man,
but not working...


Desired Output
Code:
below are data that is not the same from google.com domain
Registry Registrant ID:
Registrant Phone: +1.6502530000

Registry Admin ID:
Admin Phone: +1.6506234000



Registry Tech ID:
Tech Phone: +1.6503300100

# 4  
Just guessing at context, the OP also needs to know that whois returned data varies... (quite a bit). The record data is not uniform, there many different "valid" formats.

(something to keep in mind)
# 5  
i know this is really hard..

im pretty sure harder than google hehehe

this script should be intelliegent enough to know the difference between the fields, except for the first column of course
# 6  
It is hard. While this isn't a direct answer... I've posted my super whois.sh at:

http://endlessnow.com/ten/Source/whois-sh.txt

It at least tries to understand certain elements of the various formats returned by whois.

But it's focused at the more "core" common types. Some of the detail items you are wanting are really all over the place format wise and not well defined (if defined at all).

If it helps... great.... but maybe not for the content you are wanting...

whois is a poor database....
# 7  
when i run your script this is the output. which what i dont want


Code:
$ sh u google.com
google.com
$ sh u google
google                                                          128.177.174.32 - 128.177.174.47 128.177.174.32  128.177.174.47  128.177.174.32/28

this is the desired.


Code:

[root@logserver doms]#    whois page.com| sed -n '/Registry Registrant ID:/,/Tech Email:/p'| sed 's/Registry Tech ID:/\n\n&/'|sed 's/Registry Admin ID:/\n\n&/'


Registry Registrant ID:
Registrant Name: page Dom-Admin
Registrant Organization: page.com LLC
Registrant Street: PO Box 192307
Registrant City: Dallas



Registry Admin ID:
Admin Name: page Dom-Admin
Admin Organization: page.com LLC
Admin Street: PO Box 11111111
Admin City:  CEBU


Registry Tech ID:
Tech Name: page Dom-Admin
Tech Organization: page.com LLC
Tech Street: PO Box 2222222
Tech City: Dallas




Desired Output:
======================================================================================
For Domain page.com, below are mismatch data,  print
Registry Registrant ID:

Registry Registrant ID:
Registrant Name: page Dom-Admin
Registrant Organization: page.com LLC
Registrant Street: PO Box 192307
Registrant City: Dallas

Mismatch Data Registry Registrant ID:
Registry Admin ID:
Admin Street: PO Box 11111111
Admin City:  CEBU

Mismatch Data from Registry Registrant ID:
Registry Tech ID:
Tech Street: PO Box 2222222
===================================================================================








Example no 2. IF NO MISMATCH

Desired Output
[root@logserver doms]#    whois page.com| sed -n '/Registry Registrant ID:/,/Tech Email:/p'| sed 's/Registry Tech ID:/\n\n&/'|sed 's/Registry Admin ID:/\n\n&/'

=========================================================================
No mismatch Data
Registry Registrant ID:
Registrant Name: page Dom-Admin
Registrant Organization: page.com LLC
Registrant Street: PO Box 192307
Registrant City: Dallas
===============================================================================

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #149
Difficulty: Easy
In a 1999, Dennis Ritchie stated that Linux and the BSD operating systems were a continuation of the basis of the Unix design approach and were Unix derivatives.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diff between two time in hours in last column

Dear All I want to diff between two time(FIRST 4 COLUMN) in hours in last column. Kindly help me for same. 2013-11-23 15:51:23 2013-11-23 12:20:06 BRC023 CG 2013-11-23 15:51:23 2013-11-23 12:20:08 BRC064CG 2013-11-23 15:51:23 2013-11-22 13:17:49 BLM003 NG 2013-11-23 15:51:23 2013-11-22... (9 Replies)
Discussion started by: jaydeep_sadaria
9 Replies

2. Shell Programming and Scripting

Transpose Datefield from rows to column + Print time diff

Hi Experts, Can you please help me in transposing Datefield from rows to column and calculate the time difference for each of the Jobids: Input File: 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012 12:36:26,JOB_5350 Required Output:... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

3. Shell Programming and Scripting

serach diff filename in diff location using shell scripting

Hi, I am new to shell scripting. please help me to find out the solution. I need a script where we need to read the text file(consists of all file names) and get the file names one by one and append the date suffix for each file name as 'yyyymmdd' . Then search each file if exists... (1 Reply)
Discussion started by: Lucky123
1 Replies

4. Shell Programming and Scripting

.procmailrc and uudeview (put attachments from diff senders to diff folders)

Moderator, please, delete this topic (1 Reply)
Discussion started by: optik77
1 Replies

5. Shell Programming and Scripting

diff bw two files

Hi All, I have two files which look as below File1 serial="1" name="abc" type="employee" field="IT" serial="2" name="cde" type="intern" field="Marketing" serial="3" name="pqr" type="contractor" field="IT" serial="4" name="xyz" type="employee" field="Sales" File2 serial="1"... (3 Replies)
Discussion started by: grajp002
3 Replies

6. Shell Programming and Scripting

diff of files

Hi, I have 2 files.I want to check if file1 is contained in file2. A.txt: ----- AAA BBB B.txt: ------ CCC AAA BBB DDD I want to check if A.txt is contained in B.txt. Can it be done using SED ? (12 Replies)
Discussion started by: giri_luck
12 Replies

7. Shell Programming and Scripting

Diff b/w 2 files

Hi Masters, I have two files named file1 and file2. Both the files contains the same contents with some difference in comments,space.But no content change. I tried to find the diff between the two files to make sure that contents are same. For that i tried diff -ibw file1 file2 But... (1 Reply)
Discussion started by: ecearund
1 Replies

8. Shell Programming and Scripting

Simulate SVN diff using plain diff

Hi, svn diff does not work very well with 2 local folders, so I am trying to do this diff using diff locally. since there's a bunch of meta files in an svn directory, I want to do a diff that excludes everything EXCEPT *.java files. there seems to be only an --exclude option, so I'm not sure... (3 Replies)
Discussion started by: ackbarr
3 Replies

9. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies

Featured Tech Videos