![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare Files and Output Difference | Joesgrrrl | UNIX for Dummies Questions & Answers | 2 | 12-13-2008 09:51 PM |
| Compare two files and output diff to third file | altamaha | Shell Programming and Scripting | 8 | 09-25-2008 10:42 AM |
| compare two col from 2 files, and output uniq from file 1 | pp56825 | Shell Programming and Scripting | 2 | 01-10-2008 11:10 AM |
| compare two .dat files and if there is any difference pulled into a separate file | kirankumar | Shell Programming and Scripting | 1 | 04-19-2006 02:13 AM |
| compare 2 files, output dups to file | blt123 | UNIX for Dummies Questions & Answers | 2 | 07-15-2004 10:31 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using grep to compare files and extract the difference to another output file
I have two files with dumps of DNS zones. One old and one new. I need to take the new file to find out what was added to the zone's since the old file was given to me. and output that data into another file so we can import it to our DNS server.
I'm extremely new at Unix and am not sure how to go about doing this... I attemped to use grep -n -f olddump newdump > output.txt but it's only outputting like two domain names when i know there are hundreds of differences. |
|
||||
|
so what I do is just run it through a grep like this:
sdiff orig_file new_file |grep ">" That should show you everything that is in the new file and not in the original. You may need to just run the sdiff without the grep to see what I am talking about and you will see how it works. -Stephen |
|
||||
|
I did something along these lines not so long ago. From the comm man page:
Quote:
Code:
sort previouslist > previouslist.sorted sort newlist > newlist.sorted Code:
comm -1 -3 previouslist.sorted newlist.sorted > file.containing.just.new.zones |
|
||||
|
Below is the script i'm using. I chose grep because it's dumping the contents of all the files in the directory into one file while putting the name of the original file next to each entry.
Everything works great until I get to the point of comparing the files and outputting the difference. It seems like it's doing it line for line... for example www macklaw.com 1.x.x.x ftp macklaw.com 1.x.x.x ftp macklaw.com 1.x.x.x www macklaw.com 1.x.x.x If the above data is the way it is output it shows them as being different data, i guess because they aren't on the same line. A few of the lines got swapped around when the new dump was sent out and this is prevalent throughout the file. Is there any clean way to get an exact difference either from two different files, or two directories with a whole listing of other files into one sheet that only list the difference between the two? Quote:
|
![]() |
| Bookmarks |
| Tags |
| dns, grep, pattern matching files, scripting, unix |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|