Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

How to merge two text files?

- - - - -

  • Please log in to reply
237 replies to this topic

#26
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag
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
)

Edited by tomasz86, 10 June 2011 - 07:50 AM.

Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages


How to remove advertisement from MSFN

#27
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
To get the version of a particular file within a batch file is actually quite easy using an embedded VB script like so:

...
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

Posted Image


#28
dencorso

dencorso

    Iuvat plus qui nihil obstat

  • Supervisor
  • 5,946 posts
  • Joined 07-April 07
  • OS:98SE
  • Country: Country Flag

Donator

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
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
Also, third party and with source:
http://www.codeproje...LL/showver.aspx

jaclaz

#30
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag

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.

Edited by tomasz86, 11 June 2011 - 08:52 AM.

Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#31
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
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:

: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

Edited by bphlpt, 11 June 2011 - 10:35 AM.

Posted Image


#32
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag
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.

Edited by tomasz86, 11 June 2011 - 07:55 PM.

Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#33
dencorso

dencorso

    Iuvat plus qui nihil obstat

  • Supervisor
  • 5,946 posts
  • Joined 07-April 07
  • OS:98SE
  • Country: Country Flag

Donator

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
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag
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:

Edited by tomasz86, 26 June 2011 - 02:47 AM.

Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#35
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag
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

Edited by tomasz86, 26 June 2011 - 05:24 AM.

Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#37
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag
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...).
Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#40
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,540 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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!

#41
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag

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

Most of them are in my signature :angel

except of these also several unofficial updates for Win2k...
Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#42
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,540 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Thanks for the reply, I didn't realise you were classing those as projects.

#43
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag

I didn't realise you were classing those as projects.

Should I not? ;)

Alternatively you can say it's just a one big project called "Let's keep Windows 2000 alive!".
Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#44
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
NOT the intended "final" result, ONLY "intermediate steps".
Find attached three batches.
  • splitinf.cmd - to split an existing .inf (run it with one parameter, the original .inf)
  • join_inf.cmd - to join the split parts created by the above (run it with one parameter, the SPLIT_ directory)
  • beautify.cmd - to make the result more readable and reset some changes I have to do to the Split parts to process them easily in batch

gsar is needed:
http://home.online.no/~tjaberg/

Basically:
  • create a directory (please NO spaces in paths or filenames) like C:\INFTEST
  • put in it the batches, gsar.exe and the (basis)Windows2000-KB891861-v2-x86-ENU.EXE.inf (please rename it to something manageable, like "base2K.inf"), never use in filenames characters that are parsed by the command line, like "(", ")", "&" "|" and interpreted like commands or are however part of syntax or need to be escaped normally, even if allowed on the filesystem, see here:
    http://en.wikipedia.org/wiki/Filename
    (please note how right now the batches do use "[" and "]" so may be not good on a FAT filesystem, please use them on a NTFS one)
  • open a command prompt and navigate to the directory you made:
    CD /D C:\INFTEST
  • run:
    splitinf.cmd base2K.inf
    join_inf.cmd SPLIT_base2K
    beautify.cmd JOINED_base2K.inf
  • the "end result", i.e. BEAUTY_JOINED_base2K.inf should be comparable with the original base2K.inf and be a "fully" working .inf file

If not, post which problems there are.
Once we get these steps working successfully, we will talk about the actual merging of the "base" with another "split" file....
Also, I have noticed that in some of the "example files" there are many "empty" sections, are they actually *needed* (right now they are mantained as they are)?


Please note how the above are early, preliminary tests and the actual .cmd's need to be cleaned and polished a lot (and quite a bit of "error controls" need to be added to them).

jaclaz

Attached Files


Edited by jaclaz, 12 July 2011 - 10:37 AM.


#45
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag
Wow :w00t:

I've just done four tests:

1. A simple update.inf from a single W2K update - w2k_KB838989.inf

No problems. The only difference was in the number of spaces under [Version].

Posted Image

2. Update.inf from Update Rollup 1 for W2K - w2k_KB891861-v2.inf

There are two problems:

- "==" changes to "§#§"
- "&" changes to "§##§"

Posted Image Posted Image

3. Update.inf from Update Rollup 2 for W2K - w2k_KB891861-UR2-v2.inf

First of all, I got this when doing splitinf.cmd

Posted Image Posted Image

It continued after that. No problems occured during join_inf.cmd and beautify.cmd.

In the final file:

- "ECHO is off." was inserted several times in many different places.

Posted Image

- one line is missing (?)

Posted Image

- "mod by jaclaz" at the end of the file

Posted Image

4. Update.inf from SP4 for W2K - w2k_SP4.inf

- In SP4's update.inf there is [SourceDisksFiles] twice (each of them is different). One of them was changed.

Posted Image



As for the empty sections, they are not needed when empty and needed when not empty. There are some sections that are almost never used but there can be just one update that uses such a section. I think it's better to have them all ;)

Edited by tomasz86, 12 July 2011 - 10:24 PM.

Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#46
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
#1 is expected behaviour.
#2 is strange, the "beautify.cmd" is the one that should revert the "§#§" and "§##§" to their original values.
::Restore changes made to make the .inf "batch compatible"

::Replace dummy string "§#§" with "=="
CALL :run_gsar :xa7:x23:xa7 :x3d:x3d

::Replace dummy string "§##§" with stoopid "&"
CALL :run_gsar :xa7:x23:x23:xa7 :x26
Are you sure you did run the beatify.cmd on the file?
Anyway I will try to reproduce and fix.
#3 should mean that somehow something was a-miss (a variable got a value of "space" or "tab") I will try to reproduce and fix :unsure:, the other quirks should be easily fixable
#4 yes, this was expected in case of duplicated sections, I'll put a check for such duplicated entries so that these sections will be merged when split :w00t: (I do know that is sounds queer, but it is how it will work ;))

jaclaz

#47
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag

#2 is strange, the "beautify.cmd" is the one that should revert the "§#§" and "§##§" to their original values.

Are you sure you did run the beatify.cmd on the file?

You're right :) It was my fault. Everything O.K after running beautify.cmd.

#4 yes, this was expected in case of duplicated sections, I'll put a check for such duplicated entries so that these sections will be merged when split :w00t: (I do know that is sounds queer, but it is how it will work ;))


The problem is that (not 100% sure) this sourcedisksfiles has to be present twice in SP4's update.inf. The first one is related to the /integrate option if you want to integrate SP into W2K source CD and the other one is a normal sourcedisksfiles used when installing the update. I'm not sure but from analysing other SP's and Gurgelmeyer's USP5.1 I can say that both SourceDisksFiles are always present.
Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#48
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

The problem is that (not 100% sure) this sourcedisksfiles has to be present twice in SP4's update.inf. The first one is related to the /integrate option if you want to integrate SP into W2K source CD and the other one is a normal sourcedisksfiles used when installing the update. I'm not sure but from analysing other SP's and Gurgelmeyer's USP5.1 I can say that both SourceDisksFiles are always present.

I doubt it. :unsure:
There is nothing that can differentiate the two sections in themselves.
With the "Install XP from USB" consolidating Sections (with FEDIT) did not produce any unwanted effect, I can also mantain them "separate" by temporarily renaming them, but as I see it it would be philosophycally wrong.
I would keep the current (see attachment) consolidating approach and, once we will have solved the actual merging of two files, you will need to test if it works (as it should) with no duplicate sections.
Issue #3 was caused mainly by a question mark "?", which now is fixed.

The new version should work allright with the 4 mentioned .inf's, try with some other ones and let me know....

jaclaz

Attached Files



#49
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,520 posts
  • Joined 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag
I haven't got time to check everything thoroughly yet... but I think I found a bug ;)

1. "<=" and ">=" get changed to "< =" and "> =" respectively.

Operation = CheckFileVer, MSOERT2.DLL, >= , 6.0.0.0
becomes

Operation = CheckFileVer, MSOERT2.DLL, > = , 6.0.0.0

It doesn't work with update.exe. It must be written together.


2. I tried to merge the [SourceFilesDisks] in SP4 and indeed it doesn't seem to make any difference :)


3. Your script can already be used to merge files :> I tried some tricky thing but very simple :

copy *.inf update.inf

About 100 inf became a one big file (3000 kB). Next step was to process this file by your script. It took long time and the output file was > 250 MB ;) but the final file was sth I was looking for. Everything was merged under proper headings, the only problem was that everything was duplicated x 100 times. I used Notepad++'s sorting (TextFX) on each section separately and was able to remove duplicates this way. Still not perfect but it can save a lot of time. Your script is also very good at removing all the unnecessary spaces from an inf file.

4. I don't know why yet but the "echo is off." line is still present sometimes. Also when doing splitinf I have to press a key twice (somewhere in the middle) to make the script go on.

Edited by tomasz86, 15 July 2011 - 05:35 AM.

Posted Image
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages

#50
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
1. other two "exception" that need to be taken into consideration in the batch :blushing:
2. Good. :)
3. Hmmm, don't think it is very productive, but the fact that the batch worked (though slowly) on a 250 Mb files is good news :thumbup , it means that there are no strange "overflows" or something the like
4. The "ECHO OFF" line is good (actually "bad" ;)) news, it means that the variable that was supposed to be echoed got a null value. I need to have the .inf on which this happens, as it marks the place where the problem is. (just like #3 in previous bug report)

If you use your "inappropriate" way depicted in #3 above, and, once you create the "original" BIG MERGED file you apply to it the splitinf.cmd, then go to the SPLIT_whatever directory you should be able to process the single section files, but I don't see how by sorting them you can know which one is the line relative to the single update .inf. :unsure:

jaclaz




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users