?
Solved

Comparing two text files?

Posted on 2011-03-21
7
Medium Priority
?
734 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
[X]
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
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 96

Accepted Solution

by:
Lee W, MVP earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 96

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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

718 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