Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Comparing two text files?

Posted on 2011-03-21
7
715 Views
Last Modified: 2013-11-17
Hello,
I've been playing around with 2 files for a while now; I'm trying to find the difference in the two plain text files. I only want to output the non-matching lines & ignore white space)

I have access to Windows, Linux, or IBM's AIX [Unix] available.

I've played with, diff, comm, grep, etc, but have not gotten very far yet.

My main objective is to find out what files are missing comparing two directory structures. I'm not concerned about the file size, just the file's name.

Thanks!
0
Comment
Question by:damijim
7 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 35186081
Use diff -b to disregard differences in white spaces.

If you want to compare two directory structures, you can prepare a sorted list of the file names.

cd DIR1
ls | sort > directory1

cd DIR2
ls | sort > directory2

Now

diff directory1 directory2

or
comm directory1 directory2

This should work now because you have a sorted list of files
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 500 total points
ID: 35186123
If you can use a GUI, then try Beyond Compare.  Otherwise, you can use Notepad++ - it doesn't show "JUST" the differences, but it highlights them.
0
 
LVL 12

Expert Comment

by:tel2
ID: 35186319
A few comments on farzanj's post:

> ls | sort > directory1
I think the "sort" is not required, since "ls" automatically sorts filenames.

> cd DIR1
There's no need to "cd" to the directories.  You can do:
    ls DIR1 >directory1
    ls DIR2 >directory2
    diff directory{1,2}   # Or the full syntax
And "ls" won't show the directory1/2 names its output.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Author Comment

by:damijim
ID: 35186338
I do not have a GUI for this AIX box.

fraznaj,
I have tried that and I end up with a mess of code. i know there are only a couple missing lines between the plain text. I've tried your suggestion already and it didn't work out.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 35186376
you said "I have access to Windows"

Beyond Compare is a windows program - so I don't quite understand why it won't work.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35187714
You should use

ls -a -1

to get one-column output and to show hidden files as well. Please note that it's the digit "1", not the letter "l"!

Next, are you aware that comm provides a three-column output?

1. Lines that are only in File1
2. Lines that are only in File2
3. Lines that are in both File1 and File2.

You can suppress displaying single columns by specifying the appropriate column numbers as a flags to comm, e.g.

comm -2 -3 file1 file2

will only display column 1.

So try

ls -a1 dir1 > dir1.out
ls -a1 dir2 > dir2.out

diff -w dir1.out dir2.out
or
comm -3 dir1.out dir2.out

"-w" of "diff" ignores all spaces and tab characters and treats all other strings of blanks as equivalent. Unfortunately there is no such option with "comm".

wmp
0
 
LVL 1

Author Closing Comment

by:damijim
ID: 35191572
Sorry for the confusion. The first resolution that worked out for me was Beyond Compare. It made it really simple to find the data I needed. Thanks.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
USB backup batch file help needed. 9 106
MarkLogic 1 89
How to make a Bash alias that takes parameters 5 72
Solaris acount issues 44 26
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question