Computing.Net > Forums > Programming > Compare two text files, output diff to 3rd

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Compare two text files, output diff to 3rd

Reply to Message Icon

Name: bobsingh1
Date: June 25, 2009 at 15:31:25 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

I have tried fc and it just doesn't cut it. Two test files, filea has xxxxxx on first line and yyyyyy on second and zzzzzz on third and so on.. second file has xxxxxx and yyyyyy but no zzzzzz. I want to ouput the zzzzzz to the third file. No programming exp. plz help.



Sponsored Link
Ads by Google

Response Number 1
Name: Polygoned
Date: June 25, 2009 at 16:03:58 Pacific
Reply:

How is it that fc doesn't cut it? Is it because of all the extra stuff that comes with the output?


0

Response Number 2
Name: bobsingh1
Date: June 25, 2009 at 16:20:11 Pacific
Reply:

Exactly. If there is a way, which I could not find, to get rid of all the before and after stuff, I am game but all the switches that I tried, I could not get it done.


0

Response Number 3
Name: ghostdog
Date: June 25, 2009 at 16:36:12 Pacific
Reply:

If you can use GNU tools (see my sig coreutils), use the comm command.

C:\test>comm -3 file1.txt file2.txt

GNU win32 packages | Gawk


0

Response Number 4
Name: Polygoned
Date: June 25, 2009 at 16:38:56 Pacific
Reply:

Since you say you have no programming skills I made a fairly user friendly program of it.

@echo off
set /P file1=File one:
set /P file2=File two:
set /P output=Output file:
fc %file1% %file2% /L > tmp.txt
find /v /off "*****" tmp.txt > tmp2.txt
find /v /off "%file1%" tmp2.txt > tmp3.txt
find /v /off "%file2%" tmp3.txt > tmp4.txt
for /F "skip=6" %%t in (tmp4.txt) do echo %%t >> %output%
del tmp*.txt
echo.
echo Operation complete. Press any key to exit.
pause > nul

I know, it's not beautiful and it has some limitations but it works. Don't forget to add .txt or whatever after the file names (just in case you didn't know).


0

Response Number 5
Name: Polygoned
Date: June 25, 2009 at 16:51:25 Pacific
Reply:

Whoa. I just used my code on a large text with one word edited. Did not work well.. You should probably not use it. I don't know what to do now other than follow ghostdogs advice.


0

Related Posts

See More



Response Number 6
Name: bobsingh1
Date: June 25, 2009 at 16:59:29 Pacific
Reply:

Well.. get back to work polygoned.. just kidding!!. Thanks a bunch for trying.
To Ghostdog: I will have to convince my boss to use the tools. I doubt he will agree...


0

Response Number 7
Name: ghostdog
Date: June 25, 2009 at 17:41:49 Pacific
Reply:

>> I doubt he will agree...
tell him its to increase productivity and reducing your workload, so that you can concentrate on more important stuffs that takes time. i doubt he will disagree, unless he is living in prehistoric times.

GNU win32 packages | Gawk


0

Sponsored Link
Ads by Google
Reply to Message Icon

Outputting problem open pings in multiple wi...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Compare two text files, output diff to 3rd

Compare two text files with spaces www.computing.net/answers/programming/compare-two-text-files-with-spaces/19886.html

VB Script Compare two Text files for Duplicat www.computing.net/answers/programming/vb-script-compare-two-text-files-for-duplicat/20247.html

Merging two text files, alternating order. www.computing.net/answers/programming/merging-two-text-files-alternating-order/19292.html