Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using `diff`

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

I'm trying to use `diff` to make a list of comparisons.

test.txt looks like:

Code:
my test bla bla

sdfsdfsdf

and some line spacfffes


...and test2.txt, looks like:


Code:
my test bla bla

some extra content

sadfsdfsdf

and some line spaces


The desired output (so I can process it via a perl script, and put each side into "table cells".

The kinda thing I'm trying to end up with, is:


Now, doing something like:

Code:
user@server test $ diff  -y test.txt test2.txt
my test bla bla                                                 my test bla bla

sdfsdfsdf                                                     | some extra content

and some line spacfffes                                       | sadfsdfsdf
                                                              >
                                                              > and some line spaces


..but I really need something easier to work with - so maybe something like:


Code:
user@server test $ diff  -y test.txt test2.txt
my test bla bla                                               :  my test bla bla

sdfsdfsdf                                                     | some extra content

and some line spacfffes                                       | sadfsdfsdf
                                                              >
                                                              > and some line spaces

(i.e something seperating the lines, even when they are the same)

Anyone got any suggestions? I've been searching high and low all day for this kinda thing - and still no nearer, so thought I'd post here, to pick the minds of experts =)

TIA

Andy
 
You mention wanting to process the files with a perl script. Not to sound contrite, but how about writing a perl script to give you the desired functionality?

For example, you could open file 1, use a foreach <> loop, and the compare against file 2 with a match expression, using whatever is read in to the default variable by the diamond operator as the match expression? If desired you could put some conditionals on the match loop, such as keep comparing as long as you only encounter white space, etc.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top