MSFN Forum: How to merge two text files? - MSFN Forum

Jump to content


  • 12 Pages +
  • 1
  • 2
  • 3
  • 4
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

How to merge two text files? and sort them... Rate Topic: -----

#21 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,420
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 09 June 2011 - 12:42 PM

There is a pre-made batch, here:
http://www.robvander.../readini_nt.txt
to parse .ini files (very similar if not identical to .inf/.sif files) that can possibly be adapted to your uses.

Read also these:
http://www.msfn.org/...crets-revealed/
http://reboot.pro/3960/

Also, there is a tool, fedit.exe , here:
http://www.msfn.org/...ic/48200-fedit/

that has the "once" switch that may come useful.

The "prepare.cmd" here contains some examples of the use of fedit:
http://www.msfn.org/...y/page__st__306


jaclaz


#22 User is offline   dencorso 

  • Adiuvat plus qui nihil obstat
  • Group: Super Moderator
  • Posts: 4,862
  • Joined: 07-April 07
  • OS:98SE
  • Country: Country Flag

Posted 09 June 2011 - 01:15 PM

View Posttomasz86, on 09 June 2011 - 07:08 AM, said:

[Version]

    Signature                 = "$Windows NT$"
    Signature                 = "$Windows NT$"
	
[SourceDisksFiles]

    ipsecmon.exe=1
    remotesp.tsp=1


I don't care for duplicates now but is there any program that would do such a sorting automatically?

Even if dupes (duplicate lines) aren't you concern right now, you'll have to eliminate them, so, just for the record, the yanklines script I put together only removes exact dupes, no matter how many and where they are on the text file. It's fast and can handle really big files, because it was intended to be used with merged history logs.

#23 User is offline   bphlpt 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,075
  • Joined: 12-May 07

Posted 09 June 2011 - 01:58 PM

The comments by Yzöwl, and your own tests re version numbers of files rather than just dates, probably deserve a little more consideration. After all, depending on one's settings, sometimes just downloading or copying a file can change the date of the file - and then what?

Cheers and Regards

#24 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 09 June 2011 - 10:14 PM

Thank you for all your input. I really appreciate it :thumbup

1. As for file version checking, I know it would be the ultimate way to be sure that only newest files are copied but even now with xcopy it's not a big problem. I did a test and compared Win2k UR2 beta1 which I created 100% manually with the same hotfixes merged by this script. The results were identical. Dates may change when copying files but here they are taken from inside the hotfixes.

I'll show you some screen shots:

Posted Image

2. Removing duplicates automatically may be tough. For example, let's say in the merged update.ver we have:

agentdpv.dll=1673840A5FDD52DB9A60D8B61AAB0FCE,0002000000000D62,53008  
agentdpv.dll=3D8249606BED3456A36A1F3069BAE2A3,0002000000000D60,53008

As file size is the same, determining the correct file would require md5 checking... but as such instances are not many it's probably easier to just check it manually and remove the unnecessary lines ;)

As for the update.inf the problem with duplicates is that the same entry is used many times, ex:

[System32.Files]

    ipsecmon.exe,,,8
    oakley.dll,,,8
    polagent.dll,,,8
    polstore.dll,,,8
    rasmans.dll,,,8

[Cache.Files]

    ipsecmon.exe,,,8
    oakley.dll,,,8
    polagent.dll,,,8
    polstore.dll,,,8
    rasmans.dll,,,8

Removing duplicates would require checking only files under each heading ([...]) separately. What I was saying about not caring about such duplicates meant that even if the final update.inf looks like this:

[System32.Files]

    ipsecmon.exe,,,8
    ipsecmon.exe,,,8
    ipsecmon.exe,,,8
    polagent.dll,,,8
    polagent.dll,,,8

[Cache.Files]

    ipsecmon.exe,,,8
    ipsecmon.exe,,,8
    ipsecmon.exe,,,8
    polagent.dll,,,8
    polagent.dll,,,8

I could just use Notepad++ and sort each list manually which is quite easy to be done and would also remove the duplicates automatically.

Also, what about something like this?

sp3res.dll
sp3res.dll,,,8


3. Anyway, I'll have a look at all these scripts and try to use them. Thanks once again for all your help B)

This post has been edited by tomasz86: 09 June 2011 - 10:20 PM


#25 User is offline   dencorso 

  • Adiuvat plus qui nihil obstat
  • Group: Super Moderator
  • Posts: 4,862
  • Joined: 07-April 07
  • OS:98SE
  • Country: Country Flag

Posted 09 June 2011 - 10:14 PM

Dates can change easily. PE Timestamps not so. Since, in Win 2k, most executables are PE executables, PE Timestamps and version numbers should be enough to decide most ambiguities. I posted more about that in older posts, and below are poiters to them.

View Postdencorso, on 22 January 2011 - 09:29 AM, said:

But, when push comes to shove, you can use the PE Timestamp (see this, this, this and this) to sort things out, in many occasions (provided the files in question *are* PE executables (EXE, SYS, OCX, DLL, TLB usually)... although, in some cases it just adds to the confusion. There's nothing equivalent for NE, LE and plain DOS executables, I'm sorry to say.
Also of interest may be this old post, by Petr, on versioning.
HTH


#26 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 10 June 2011 - 07:33 AM

I haven't had time yet to check all this information. For now I've just sorted and tidied the script up. I want to keep is as simple as possible.

@ECHO OFF
COLOR 1F
IF EXIST HF\*.EXE (
	IF EXIST HFMER RD/Q/S HFMER 
	IF EXIST TEMP RD/Q/S TEMP
	MD HFMER TEMP
	DIR/B/A-D/OGN/ON HF\*.EXE>TEMP\HF.TXT
	SET HF=
	FOR /F %%I IN (TEMP\HF.TXT) DO (SET HF=%%I&IF DEFINED HF CALL :HFEXTRACT)
	DEL/Q/S TEMP\HF.TXT
)
IF NOT EXIST HF\*.EXE (
	ECHO HF folder is empty.
	ECHO.
	PAUSE
	EXIT
)

:HFEXTRACT
ECHO Unpacking %HF%
MD TEMP\HF&START/WAIT HF\%HF% /Q /X:TEMP\HF
ECHO.
XCOPY/DEHRY TEMP\HF HFMER
IF EXIST TEMP\HF\UPDATE\update.inf MOVE TEMP\HF\UPDATE\update.inf TEMP\%HF%.inf
IF EXIST TEMP\HF\UPDATE\update_w2k.inf MOVE TEMP\HF\UPDATE\update_w2k.inf TEMP\%HF%.inf
MOVE TEMP\HF\UPDATE\update.ver TEMP\%HF%.ver
RD/Q/S TEMP\HF
ECHO.

IF NOT EXIST TEMP\HF.TXT (
	FOR /F %%A IN ('dir /b TEMP\*.ver') DO (
	FOR /F "skip=1 tokens=*" %%B IN (TEMP\%%A) DO (
	ECHO Merging update.ver...
	ECHO TEMP\%%A -- %%B
	ECHO %%B >>TEMP\update.txt
	) 
	) 
	ECHO [SourceFileInfo] >HFMER\UPDATE\update.ver
	SORT TEMP\update.txt >>HFMER\UPDATE\update.ver
	DEL/Q/S HFMER\UPDATE\update.inf HFMER\createcab.cmd
	COPY TEMP\*.inf HFMER\UPDATE
	RD/Q/S TEMP
)


This post has been edited by tomasz86: 10 June 2011 - 07:50 AM


#27 User is offline   bphlpt 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,075
  • Joined: 12-May 07

Posted 10 June 2011 - 10:40 PM

To get the version of a particular file within a batch file is actually quite easy using an embedded VB script like so:

Quote

...
IF NOT EXIST TMP\FILEVER.VBS (CALL :sub_FileVerScript)
FOR /F %%G IN ('CSCRIPT //NOLOGO TMP\FILEVER.VBS FileYouWantToKnowTheVersionOf') DO (
...
At this point "%%G" will be the version of the file in question so do whatever you need to do with it
...
)

...

:: This is the subroutine that creates the VB script to get the version info
:sub_FileVerScript
>>TMP\FILEVER.VBS (
ECHO Option Explicit
ECHO Dim FSystem
ECHO Set FSystem = CreateObject^("Scripting.FileSystemObject"^)
ECHO WScript.Echo FSystem.GetFileVersion^(WScript.Arguments^(0^)^)
ECHO Set FSystem = Nothing
)
EXIT /B
...


(Note: Escaping the left-hand parenthesis "^(" is not required, but I usually do it anyway to be symmetrical. :) )

Hope this is useful.

Cheers and Regards

#28 User is offline   dencorso 

  • Adiuvat plus qui nihil obstat
  • Group: Super Moderator
  • Posts: 4,862
  • Joined: 07-April 07
  • OS:98SE
  • Country: Country Flag

Posted 11 June 2011 - 03:18 AM

Well... The official MS way to get an MD-5 hash is FCIV and to get File Versions it's FILEVER, findable inside this package. The're both console command-line tools, useful also in batch files.

#29 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,420
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 11 June 2011 - 03:38 AM

Also, third party and with source:
http://www.codeproje...LL/showver.aspx

jaclaz

#30 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 11 June 2011 - 08:51 AM

View Postbphlpt, on 10 June 2011 - 10:40 PM, said:

To get the version of a particular file within a batch file is actually quite easy using an embedded VB script like so:

I get this when trying to run the script
Posted Image
My system is Windows 2000.

This post has been edited by tomasz86: 11 June 2011 - 08:52 AM


#31 User is offline   bphlpt 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,075
  • Joined: 12-May 07

Posted 11 June 2011 - 10:21 AM

Sorry it didn't work for you. It's been a while since I've run Win2K, after running it for ~10 years. The above standalone script has only been tested, by me, on XP and Win7 x32. I didn't think about it possibly having a problem on Win2K, though I'm not sure why it should. I found it in Strel's SNMSynth program, http://www.msfn.org/...8-w2kxp2k3-x86/, which I believe is supposed to run on Win2K. So I'm confused.

The original code snippet is this:

Quote

:FILEVERSCRIPT
ECHO>>TMP\FILEVER.VBS Option Explicit
ECHO>>TMP\FILEVER.VBS Dim FSystem
ECHO>>TMP\FILEVER.VBS Set FSystem = CreateObject^("Scripting.FileSystemObject"^)
ECHO>>TMP\FILEVER.VBS WScript.Echo FSystem.GetFileVersion^(WScript.Arguments^(0^)^)
ECHO>>TMP\FILEVER.VBS Set FSystem = Nothing
GOTO :EOF


Cheers and Regards

This post has been edited by bphlpt: 11 June 2011 - 10:35 AM


#32 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 11 June 2011 - 07:54 PM

I don't know if it's me doing something wrong or the script is wrong but I tested it on 3 different systems (w2k adv srv, w2k pro, xp pro) and always got errors... :/ On the other hand, I've been using SNMSynch with no problems here.

This post has been edited by tomasz86: 11 June 2011 - 07:55 PM


#33 User is offline   dencorso 

  • Adiuvat plus qui nihil obstat
  • Group: Super Moderator
  • Posts: 4,862
  • Joined: 07-April 07
  • OS:98SE
  • Country: Country Flag

Posted 11 June 2011 - 11:56 PM

Codeboxes are adding trailing spaces, of late. I believe jaclaz was the first to report it. Check you script for trailing spaces and be sure to remove them. They can be a PITA because they break otherwise working programs sometimes, but you don't usually see them, unless you're looking for them. This is a longshot, by maybe it'll solve your issue.

#34 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 26 June 2011 - 02:45 AM

Actually there was something wrong with my system, not with the script :P I reinstalled everything any now FILEVER.VBS seems to work as it is. I also found a use for dencorso's yanklines script to remove duplicates from update.ver.

The real problem is update.inf. What has to be done is to merge everything according to headings in each update.inf file and then remove duplicates but only under the same heading. I don't know how to do it yet :lol: If I use yanklines for the whole update.inf, all duplicates are indeed removed but some identical lines must exist under different headings - yanklines removes all of them :(

At this moment I just use Kdiff3 to merge update.infs as it takes less time than thinking how to prepare a script to do it automatically :lol:

This post has been edited by tomasz86: 26 June 2011 - 02:47 AM


#35 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,420
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 26 June 2011 - 04:31 AM

Have you actually tried FEDIT?

Can you post a single example of a "base" update.inf + a couple examples of the files to be merged?

jaclaz

#36 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 26 June 2011 - 05:02 AM

Yes, I downloaded and checked all tools mentioned in this topic but I don't really know how I could use FEDIT when merging these files :/

Here is an example (fragments only as full update.inf files are very long)

Full update.inf files here: http://www.mediafire...nfs_to_merge.7z

1.inf
Spoiler


2.inf

Spoiler

This post has been edited by tomasz86: 26 June 2011 - 05:24 AM


#37 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,420
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 26 June 2011 - 12:45 PM

You are right these particular .inf files need some "special treatment".
There are lots of "beautifying" uneeded spaces that create havoc! :ph34r:
Additionally you simply cannt write properly with FEDIT something that is ALREADY between double quotes (like "$Windows NT$").

I'll do some tests with batch and a bunch of utilities and let you know.

jaclaz

#38 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,420
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 28 June 2011 - 04:24 AM

View Postjaclaz, on 26 June 2011 - 12:45 PM, said:

I'll do some tests with batch and a bunch of utilities and let you know.

Did some tests, and the matter is a bit complex, but now I can say it can be done, though not with "ini related" tools, since the .inf seem like having a "queer" set of rules.

Don't expect anything too soon, but I have great expectations from a new approach I just took ... :)

jaclaz

#39 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 28 June 2011 - 05:20 AM

Thank you very much for your interest.

Don't worry and just take your time :) It's better not to be too hasty when doing these things (as I experienced myself when doing some of my projects...).

#40 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,363
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 28 June 2011 - 07:58 AM

View Posttomasz86, on 28 June 2011 - 05:20 AM, said:

It's better not to be too hasty when doing these things (as I experienced myself when doing some of my projects...).

I'm interested to know which projects you've done!

Share this topic:


  • 12 Pages +
  • 1
  • 2
  • 3
  • 4
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy