Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 11-13-2014, 03:51 PM   #1
LQ Newbie
Registered: Oct 2010
Location: Taylorsville, KY, USA
Distribution: RHEL, Fedora, CentOS, Ubuntu & HP-UX
Posts: 22

Rep: Reputation: 0
Unhappy comparing two files down to the parts of a line in the file

Good day everyone,

Thank you in advance for any assistance you can provide. Here is my boggle. I'm working on a Centos 6.5 server where I'm pulling an active directory group with winbind. I'm using wbinfo to obtain the listing of the domain admins group to check if there is a difference so I can add those new admins to approximately 300 servers. I am using Chef to push it out through a recipe.

O.k., there is a short history. I'm using the following command to pull the info from AD:

wbinfo --group-info "domain admins" > sysadmin.txt

Which gives me the following output:

domain admins:*:12345678:me,you,them

I then copy that file to sysadmin_old.txt and then run the wbinfo command again and compare the new file with the old file. So, the two files look like this:

domain admins:*:12345678:me,you,them

domain admins:*:12345678:me,you,them,us

I am trying to get the true difference between these two files; "us" into a 3rd file named diff.txt.

So, the diff.txt file will look like this:


I have used the following with no success:

grep -F -x sysadmin_old.txt sysadmin.txt > diff.txt
grep -f sysadmin_old.txt sysadmin.txt
diff -u sysadmin_old.txt sysadmin.txt | grep -E "^\+"
comm -1 sysadmin_old.txt sysadmin.txt
comm -2 sysadmin_old.txt sysadmin.txt
comm -3 sysadmin_old.txt sysadmin.txt
comm -13 sysadmin_old.txt sysadmin.txt
grep -Fxvf sysadmin_old.txt sysadmin.txt > diff.txt
diff sysadmin_old.txt sysadmin.txt | grep "<" | sed 's/^<//g' > diff.txt
sort sysadmin_old.txt sysadmin.txt | uniq -u > diff.txt
diff sysadmin_old.txt sysadmin.txt | perl -lne 'print $1 if(/^\> (.*)/)'

I have spent the last several hours googling this issue and have been unsuccessful. Any help you can provide is greatly appreciated. I will admit I am just now learning sed and awk, so there may be a solution there that I have not found.

Thank you!

Old 11-14-2014, 10:33 AM   #2
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
I'm not very proficient with awk or sed either, but perhaps dwdiff will do what you want.
Using the following command:
dwdiff -P -3 sysadmin_old.txt sysadmin.txt
yields this output:
You could pipe this to awk with "FS="+" to obtain ",us" and then pipe to "tr" to get rid of the comma(s).

3 members found this post helpful.
Old 11-14-2014, 02:57 PM   #3
LQ Newbie
Registered: Oct 2010
Location: Taylorsville, KY, USA
Distribution: RHEL, Fedora, CentOS, Ubuntu & HP-UX
Posts: 22

Original Poster
Rep: Reputation: 0

Thank you!!!! I'm not familiar with dwdiff. Installed it and it worked perfectly!

I'll mark as solved and add this to my bag of goodies.



centos6, comm, diff, file, join

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing to specific line in file bash script ShiGua Linux - Newbie 3 11-16-2012 04:42 PM
How to read a data from a file as parts and save in different files mohan.jiggy Programming 5 10-15-2012 08:46 AM
Writing multiple files from one file after comparing each line jlrod912 Linux - Newbie 2 06-26-2012 03:05 PM
[SOLVED] Comparing two files and looking for the same line based on field - awk sopier Programming 8 12-26-2011 02:53 PM
[SOLVED] spliting a text file into several parts by line count clstanton Linux - Newbie 2 09-21-2009 01:49 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:32 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration