Solved

Comparing two text files?

Posted on 2011-03-21
7
712 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

785 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