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

#151
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
double post :ph34r:

Edited by tomasz86, 06 March 2012 - 06:12 AM.

post-47483-1123010975.png



How to remove advertisement from MSFN

#152
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
Hmm, I'm not sure if that's the case. I've never experienced this problem before. In this case the first [System32.Files] seems to be ignored. I added "abc" to the second [System32.files] so now the two should be merged (as it's in case of other sections) but in the final file only "abc" is present under [System32.Files].

update.inf

BEAUTY_JOINED_update.inf

The script isn't case sensitive, is it?? It's [System32.files] vs [System32.Files] here.

@EDIT

It is case sensitive :} Is there any simple way to make it case insensitive?

@EDIT2

I'm just kind of guessing but maybe

IF /I "%%?"=="%Section%" SET dupe_Flag=1
instead of

IF "%%?"=="%Section%" SET dupe_Flag=1
?

Edited by tomasz86, 06 March 2012 - 06:26 AM.

post-47483-1123010975.png


#153
jaclaz

jaclaz

    The Finder

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

I'm just kind of guessing but maybe

IF /I "%%?"=="%Section%" SET dupe_Flag=1
instead of

IF "%%?"=="%Section%" SET dupe_Flag=1
?

A very educated guess :thumbup
jaclaz

#154
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
By the way, I added these lines to splitinf.cmd and beautify.cmd:


1. splitinf.cmd

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

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

::Replace even more stoopid ">=" with a dummy string "§#######§"
CALL :run_gsar :x3E:x3d  :xa7:x23:x23:x23:x23:x23:x23:x23:xa7

::Replace even more stoopid "<=" with a dummy string "§########§"
CALL :run_gsar :x3C:x3d  :xa7:x23:x23:x23:x23:x23:x23:x23:x23:xa7


2. beautify.cmd

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

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

::Replace a dummy string "§#######§" with even more stoopid ">="
CALL :run_gsar :xa7:x23:x23:x23:x23:x23:x23:x23:xa7 :x3E:x3d

::Replace a dummy string "§########§" with even more stoopid "<="
CALL :run_gsar :xa7:x23:x23:x23:x23:x23:x23:x23:x23:xa7 :x3C:x3d

so now not only "==" but also ">=" & "<=" are processed correctly.

post-47483-1123010975.png


#155
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,821 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
After all the work you've done with these various tools you've used and modified, would you please post all the current scripts/tools you use with a very brief description of how you use them, or are they all already conveniently available in one place?


Cheers and Regards

Posted Image


#156
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
No problem but I'd like to finish the script first. At this moment it still needs many fixes and addtions to be fully functional, especially concerning the SP part (merging updates works more or less). There are some issues with it too which I must fix before making it public, ex. the script now works in Windows 2000 only and doesn't in other versions of Windows, not even in XP.

post-47483-1123010975.png


#157
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
I added one more lines to splitinf.cmd:
::Replace even more stoopid "|" with a dummy string "§#########§"
CALL :run_gsar :x7c  :xa7:x23:x23:x23:x23:x23:x23:x23:x23:x23:xa7

and one to beautify.cmd:
::Replace a dummy string "§#########§" with even more stoopid "|" 
CALL :run_gsar :xa7:x23:x23:x23:x23:x23:x23:x23:x23:x23:xa7 :x7c

because some lines with "|" simply disappeared after running splitinf.cmd.

By the way, jaclaz, is there any particular reason to use the "§" character and not any other one? It gets "butchered" when system locale is set to some languages (Chinese, Korean, Japanese for sure) and therefore the final output is not correct.

Edited by tomasz86, 20 April 2012 - 04:35 AM.

post-47483-1123010975.png


#158
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
Has anyone got any idea how to process such lines automatically:

ELK_LOCALE_INUSE_201a=\
 "sth1"
ELK_MUI_INUSE_046e=\
 "sth2"
and get this:

ELK_LOCALE_INUSE_201a="sth1"
ELK_MUI_INUSE_046e="sth2"
? I've tried many different ways but can't get through it :/ I guess my commandline knowledge is too limited... There are different lines inbetween too.

Edited by tomasz86, 21 April 2012 - 06:41 AM.

post-47483-1123010975.png


#159
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,814 posts
  • Joined 13-January 06
This should do it (sed.exe is needed and is a port of gnu sed from the unix tools) :
type file| sed ":a;N;$!ba;s/=\\\n\ /=/g"


#160
jaclaz

jaclaz

    The Finder

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

By the way, jaclaz, is there any particular reason to use the "§" character and not any other one? It gets "butchered" when system locale is set to some languages (Chinese, Korean, Japanese for sure) and therefore the final output is not correct.

You find another "rarely" used character and it will do.
I have it (the §) on my keyboard, so I tend to use it.
Though I cannot see how it can become "butchered", as it is simply an intermediate step, and it is "added" bu a batch and "removed" by the next. :unsure:
In any case the idea of §<n*#>§ is simply that of having an "unlikely to be present in a .inf/.ini/.sif" string for substitution, to reèplace characters that are not parsable by a batch.

The:

ELK_LOCALE_INUSE_201a=\
"sth1"

is most probably a =\CR+LF" sequence. If yes, you can use gsar allright.

jaclaz

#161
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
I think the problem with "§" is that when I set system locale to Korean and then run the script something like "==" becomes "??" instead of "§#§" so the beautify.cmd part cannot work properly.

The "§" seems to be processed incorrectly by cmd.exe for certain system locales. There's no problem when I set it to Polish.

Edited by tomasz86, 23 April 2012 - 06:26 AM.

post-47483-1123010975.png


#162
jaclaz

jaclaz

    The Finder

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

I think the problem with "§" is that when I set system locale to Korean and then run the script something like "==" becomes "??" instead of "§#§" so the beautify.cmd part cannot work properly.

The "§" seems to be processed incorrectly by cmd.exe for certain system locales. There's no problem when I set it to Polish.

It must be something connected to Codepage (or NLS, or *whatever*) :unsure:.
You can try using instead of the "§" an "unlikely to be used character within the first 127 ASCII:
http://www.asciitable.com/
A good candidate (actually two of them could be "{" and "}" (with the side effect of looking more nice)

jaclaz

#163
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
It's not codepage because I tried to set it manually in cmd.exe (CHCP command) but the effect was still the same. I've replaced all "xa7" with "x7b" ("{") and it seems to work OK now. Thank you :)

EDIT: I also had to change the line

ECHO §mod by jaclaz>%Work%
to

ECHO {mod by jaclaz>%Work%
in join_dedupe.inf.cmd.

Edited by tomasz86, 24 April 2012 - 09:48 AM.

post-47483-1123010975.png


#164
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag

The:

ELK_LOCALE_INUSE_201a=\
"sth1"

is most probably a =\CR+LF" sequence. If yes, you can use gsar allright.

I didn't know how to do it with gsar so I've prepared this script:

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

FOR /F "tokens=* delims=*" %%I IN ([Strings]update.inf) DO (
	SET STRING=
	FOR /F "tokens=2 delims==" %%J IN ("%%I") DO (
		IF "%%J"=="\" (
			SET STRING=1
			FOR /F "tokens=1 delims==" %%K IN ("%%I") DO (
				SET STRING1=%%K
			)
		)
	)
	IF NOT DEFINED STRING IF DEFINED STRING1 (
		SET STRING2=%%I
		ECHO>>[Strings]update.inf.temp !STRING1!=!STRING2:~1!
		SET STRING1=
	) ELSE (
		ECHO>>[Strings]update.inf.temp %%I
	)
)

post-47483-1123010975.png


#165
jaclaz

jaclaz

    The Finder

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

I didn't know how to do it with gsar so I've prepared this script:

Yep, but why making it more complex than needed?
gsar is already among the used tools if I remember correctly, and it's usage is pretty much simple:
rem change "\CR+LF"    to "SPACE"
gsar  -o  "-s:x5C:x0D:x0A" "-r:x20" "filename"
should do.

jaclaz

#166
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,821 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
For those not familiar with gsar syntax, as I wasn't, here is the gsar.txt file contents:

Spoiler


Cheers and Regards

Edited by bphlpt, 23 May 2012 - 04:21 AM.

Posted Image


#167
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
@jaclaz

Thanks. It works fine.


I've found one bug in beautify.cmd.

This:

::Add a single CR+LF after each Section
CALL :run_gsar :x5d :x5d:x0d:x0a
makes this kind of a line:

HKLM,"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1","PMDisplayName",0x00000000,"Local intranet [Protected Mode]"
become

HKLM,"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1","PMDisplayName",0x00000000,"Local intranet [Protected Mode]
"

post-47483-1123010975.png


#168
jaclaz

jaclaz

    The Finder

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

I've found one bug in beautify.cmd.

Yep, that is "expected".
The original assumption was that a "]" is only used for "Section".
Just re-process the line, this should do:
::Remove CR+LF after a ] and before a " followed by a CR+LF
CALL :run_gsar ::x5d:x0d:x0a:x34:x0d:x0a :x5d:x34:x0d:x0a

jaclaz

#169
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
I'm uploading a fixed version of the script after adding all the changes mentioned above. I listed all changes in "changelog.txt".

I'm not sure about one thing though. I changed this:

::Check if it is a Registry entry
IF "!This_token:~0,5!"=="HKLM," (
ECHO Registry Entry: !Full_Line!
ECHO !Full_Line!>>%Split_dir%\!Section!%Inf_name%
GOTO :EOF
)
IF "!This_token:~0,5!"=="HKCR," (
ECHO Registry Entry: !Full_Line!
ECHO !Full_Line!>>%Split_dir%\!Section!%Inf_name%
GOTO :EOF
)
to

::Check if it is a Registry entry
IF "!This_token:~0,5!"=="HKLM," (
ECHO Registry Entry: !Full_Line!
ECHO !Full_Line!>>%Split_dir%\!Section!%Inf_name%
GOTO :EOF
)
IF "!This_token:~0,5!"=="HKCR," (
ECHO Registry Entry: !Full_Line!
ECHO !Full_Line!>>%Split_dir%\!Section!%Inf_name%
GOTO :EOF
)
IF "!This_token:~0,5!"=="HKCU," (
ECHO Registry Entry: !Full_Line!
ECHO !Full_Line!>>%Split_dir%\!Section!%Inf_name%
GOTO :EOF
)
IF "!This_token:~0,5!"=="HKR," (
ECHO Registry Entry: !Full_Line!
ECHO !Full_Line!>>%Split_dir%\!Section!%Inf_name%
GOTO :EOF
)
but in case of the last one, i.e. "HKR," I guess I should change the whole line to

"!This_token:~0,4!"=="HKR,"
Am I right?

By the way, is there any reason ":run_gsar" is different in case of "splitinf.cmd" / "join_dedupe_inf.cmd" and "beautify.cmd"?

splitinf.cmd / join_dedupe_inf.cmd
:run_gsar
FOR /F "tokens=2 delims=:" %%A IN ('gsar -s%1 -r%2  -o  %Work%') DO ECHO %%A   	%1 -^> %2&SET Loop_Flag=1
GOTO :EOF
but

beautify.cmd
:run_gsar
FOR /F "tokens=2 delims=:" %%A IN ('gsar -s%1 -r%2  -o  %Work%') DO ECHO %%A   	%1 -^> %2&SET Loop_Counter=1
GOTO :EOF

Attached Files


Edited by tomasz86, 26 June 2012 - 02:50 AM.

post-47483-1123010975.png


#170
jaclaz

jaclaz

    The Finder

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

but in case of the last one, i.e. "HKR," I guess I should change the whole line to

"!This_token:~0,4!"=="HKR,"
Am I right?

Yep.

By the way, is there any reason ":run_gsar" is different in case of "splitinf.cmd" / "join_dedupe_inf.cmd" and "beautify.cmd"?

splitinf.cmd / join_dedupe_inf.cmd

:run_gsar
FOR /F "tokens=2 delims=:" %%A IN ('gsar -s%1 -r%2  -o  %Work%') DO ECHO %%A   	%1 -^> %2&SET Loop_Flag=1
GOTO :EOF
but

beautify.cmd
:run_gsar
FOR /F "tokens=2 delims=:" %%A IN ('gsar -s%1 -r%2  -o  %Work%') DO ECHO %%A   	%1 -^> %2&SET Loop_Counter=1
GOTO :EOF

NOT really, I guess that at the time I once thoght "let's use Loop_Counter" and another time I thought "let's use Loop_Flag".

Maybe you could simplify with:
::Check if it is a Registry entry 
IF "!This_token:~0,2!"=="HK" ( 
ECHO Registry Entry: !Full_Line! 
ECHO !Full_Line!>>%Split_dir%\!Section!%Inf_name% 
GOTO :EOF 
)
but cannot say if it would be too "wide".

jaclaz

#171
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
Here is the final version: Attached File  split_inf_8.7z   3.28KB   8 downloads

I've disabled these lines in beautify.cmd:

::Add a single CR+LF after each Section
CALL :run_gsar :x5d :x5d:x0d:x0a

::Remove CR+LF after a ] and before a " followed by a CR+LF
CALL :run_gsar ::x5d:x0d:x0a:x34:x0d:x0a :x5d:x34:x0d:x0a
as there were some lines with "[" and "]" in the middle of a line followed by various characters so I think it's safer to just not have a CR+LF after sections.


I've also added one more exception to splitinf.cmd:

::Replace even more stoopid "id=" with a dummy string "}##########}"
CALL :run_gsar :x69:x64:x3d  :x7b:x23:x23:x23:x23:x23:x23:x23:x23:x23:x23:x7b
as there are sometimes URLs like this present in the update.inf:

http://go.microsoft.com/fwlink/?linkid=57014&lcid=0x409
and they were broken by:

::normalize "=" with one space on each side
CALL :run_gsar :x3d  :x20:x3d:x20
from beautify.cmd.


Actually I've decided to change the way I use the script to this:

First part:
Spoiler

Second part:
Spoiler


I basically removed the whole splitting part from splitinf.cmd leaving only the first one related to file preparation (removing empty lines, replacing characters, etc.). Then I'm using a batch script to split it into separate files and then to join them too. Split_dedupe_inf.cmd is not used at all. Fedit.exe is also not required. After joining the parts into one file the script from beautify.cmd is used to bring back the original characters and add two CR+LFs after each section.

In fact, I've replaced the whole join_dedupe_inf.cmd with this 6-liner:

SETLOCAL ENABLEDELAYEDEXPANSION
SET SPLITDIR=%~dp1SPLIT_%~n1
SET WORK=%~f1
ECHO(>"!WORK!"
FOR /F "tokens=* delims=" %%I IN (!SPLITDIR!\[1ndex].inf) DO IF EXIST "!SPLITDIR!\%%I.inf" COPY/B "!WORK!"+"!SPLITDIR!\%%I.inf" "!WORK!"
RD/Q/S !SPLITDIR!

Edited by tomasz86, 18 July 2012 - 07:45 PM.

post-47483-1123010975.png


#172
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
I think that this line:

::Restore changes made to make the .inf "batch compatible"
::normalize "=" with one space on each side
CALL :run_gsar :x3d  :x20:x3d:x20

should be removed from beautify.cmd all together. It breaks lines like this one

HKLM,"SOFTWARE\MozillaPlugins\@microsoft.com/WPF,version=3.5","GeckoVersion", ,"1.7.2"

by putting spaces in it:

HKLM,"SOFTWARE\MozillaPlugins\@microsoft.com/WPF,version = 3.5","GeckoVersion", ,"1.7.2"

post-47483-1123010975.png


#173
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
I've got a big problem with sections like this:

[ASUSP2B-DS02/03/99]
AcpiOemId="FACP","ASUS  "
AcpiOemTableId="FACP","P2B-DS  "
AcpiOemRevision="<=","FACP",58582e31
AcpiCreatorRevision="<=","FACP",31303030

The script cannot create files "[ASUSP2B-DS02/03/99].inf" because of "/" in the name. Is there any solution to this except for replacing all "/"'s with other symbols using gsar?

post-47483-1123010975.png


#174
jaclaz

jaclaz

    The Finder

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

The script cannot create files "[ASUSP2B-DS02/03/99].inf" because of "/" in the name. Is there any solution to this except for replacing all "/"'s with other symbols using gsar?

It's not a "script" issue, it is simply a non acceptable character in a filename... :whistle:
http://en.wikipedia.org/wiki/Filename

You should replace them with (for example) - (minus or dash) or _ (underscore).

jaclaz

#175
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
At the moment I've added this:

::Replace even more stoopid "/" with a dummy string "}#######}"
CALL :run_gsar :x2f  :x7b:x23:x23:x23:x23:x23:x23:x23:x7b

I guess I'll have to do the same with other "unacceptable" filename characters (some of them are already present - you added them ;)).

post-47483-1123010975.png





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users