How to merge two text files? and sort them...
Posted 09 June 2011 - 12:42 PM
to parse .ini files (very similar if not identical to .inf/.sif files) that can possibly be adapted to your uses.
Read also these:
Also, there is a tool, fedit.exe , here:
that has the "once" switch that may come useful.
The "prepare.cmd" here contains some examples of the use of fedit:
Posted 09 June 2011 - 01:15 PM
[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.
Posted 09 June 2011 - 01:58 PM
Cheers and Regards
Posted 09 June 2011 - 10:14 PM
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:
2. Removing duplicates automatically may be tough. For example, let's say in the merged update.ver we have:
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?
3. Anyway, I'll have a look at all these scripts and try to use them. Thanks once again for all your help
This post has been edited by tomasz86: 09 June 2011 - 10:20 PM
Posted 09 June 2011 - 10:14 PM
Also of interest may be this old post, by Petr, on versioning.
Posted 10 June 2011 - 07:33 AM
@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
Posted 10 June 2011 - 10:40 PM
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
ECHO Option Explicit
ECHO Dim FSystem
ECHO Set FSystem = CreateObject^("Scripting.FileSystemObject"^)
ECHO WScript.Echo FSystem.GetFileVersion^(WScript.Arguments^(0^)^)
ECHO Set FSystem = Nothing
(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
Posted 11 June 2011 - 08:51 AM
Posted 11 June 2011 - 10:21 AM
The original code snippet is this:
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
Cheers and Regards
This post has been edited by bphlpt: 11 June 2011 - 10:35 AM
Posted 11 June 2011 - 07:54 PM
This post has been edited by tomasz86: 11 June 2011 - 07:55 PM
Posted 11 June 2011 - 11:56 PM
Posted 26 June 2011 - 02:45 AM
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 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
This post has been edited by tomasz86: 26 June 2011 - 02:47 AM
Posted 26 June 2011 - 05:02 AM
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
This post has been edited by tomasz86: 26 June 2011 - 05:24 AM
Posted 26 June 2011 - 12:45 PM
There are lots of "beautifying" uneeded spaces that create havoc!
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.
Posted 28 June 2011 - 04:24 AM
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 ...
- ← Copying single file from USB/network drive to multiple folders on C:
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- Find actual total physical memory →