How to merge two text files? and sort them...
#21
Posted 09 June 2011 - 12:42 PM
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
Posted 09 June 2011 - 01:15 PM
tomasz86, 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
Posted 09 June 2011 - 01:58 PM
Cheers and Regards
#24
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:
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
This post has been edited by tomasz86: 09 June 2011 - 10:20 PM
#25
Posted 09 June 2011 - 10:14 PM
dencorso, on 22 January 2011 - 09:29 AM, said:
Also of interest may be this old post, by Petr, on versioning.
HTH
#26
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
#27
Posted 10 June 2011 - 10:40 PM
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
Posted 11 June 2011 - 03:18 AM
#29
Posted 11 June 2011 - 03:38 AM
#30
Posted 11 June 2011 - 08:51 AM
#31
Posted 11 June 2011 - 10:21 AM
The original code snippet is this:
Quote
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
Posted 11 June 2011 - 07:54 PM
This post has been edited by tomasz86: 11 June 2011 - 07:55 PM
#33
Posted 11 June 2011 - 11:56 PM
#34
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
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
#35
Posted 26 June 2011 - 04:31 AM
Can you post a single example of a "base" update.inf + a couple examples of the files to be merged?
jaclaz
#36
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
1.inf
2.inf
This post has been edited by tomasz86: 26 June 2011 - 05:24 AM
#37
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.
jaclaz
#38
Posted 28 June 2011 - 04:24 AM
jaclaz, on 26 June 2011 - 12:45 PM, said:
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
Posted 28 June 2011 - 05:20 AM
Don't worry and just take your time
#40
Posted 28 June 2011 - 07:58 AM
- ← 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 →



Help

Back to top











