• Announcements

    • xper

      MSFN Sponsorship and AdBlockers!   07/10/2016

      Dear members, MSFN is made available via subscriptions, donations and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, become a site sponsor and ads will be disabled automatically and by subscribing you get other sponsor benefits.
tomasz86

How to merge two text files?

238 posts in this topic

double post :ph34r:

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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"

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

For those not familiar with gsar syntax, as I wasn't, here is the gsar.txt file contents:

[quote]          NAME
gsar - General Search And Replace utility


SYNOPSIS
gsar [options] [infile(s)] [outfile]


DESCRIPTION
gsar (General Search And Replace) is a utility for search-
ing for and --- optionally --- replacing strings in both
text and binary files. The search and replace strings can
contain all kinds of characters (0--255), i.e. Ctrl char-
acters and extended ASCII as well.

The algorithm used is a variation of the Boyer-Moore
search algorithm, modified to search binary files. As a
result of this, gsar is blindingly fast.

Opposed to line oriented search programs (like grep(1)),
gsar will find all matches on a line. Actually, gsar
doesn't know anything about lines at all, all files and
strings are treated as binary.

Gsar can search one or several files for a string and
report the occurrences. Gsar can read one file, search for
a string, replace it with some other string, and create a
new file containing the changes. Gsar can perform a search
and replace in multiple files, overwriting the originals.
Finally, gsar can work as a filter, reading from standard
input and writing to standard output.


OPTIONS
All options can be concatenated into one single option i.e
the command: gsar -i -b -l is the same as gsar -ibl

An option which takes an argument must be the last one in
the concatenated option, since the rest of the option is
taken as a possible argument.

Fields enclosed in [] are optional, but mandatory when
enclosed in . Options are case sensitive i.e -b is not
the same as -B.

If no options are given, gsar just gives a brief help mes-
sage.

[infile(s)]
Name(s) of input file(s) (wildcards allowed on most Unix
shells and most DOS compilers). If the -F option is used
input is taken from stdin.

[outfile]
Name of output file that is to contain the replacements.
If the -F option is used, transformed output is sent to
stdout.

-s
String to search for in file. Ctrl characters can be
entered by using a `:' in the string followed by the ASCII
value of the character. The value is entered using a `:'
followed by three decimal digits or `:x' followed by two
hex numbers. To enter a colon ( in the search pattern
use `::'. The string must follow directly after s.

Example: To search for the string :foo (`o' is 111 deci-
mal, 6F in hex) use the search options:
-s::foo or -s::fo:111 or -s::fo:x6F

If you want to search for a string with spaces in it,
under MSDOS surround the expression with quotes. Under
Unix, use the mechanisms your shell provides (commonly
quotes) to include space or other special characters.

Example: search for gsar is fast use:
gsar "-sgsar is fast" foobar.txt

The precompiled MSDOS executable in the archive supports
response files. Just put you gsar commands into a file and
put a `@' in front of the filename on the gsar command
line.

Example: file foobar.txt contains -ssupercalifragilistic-
expialidocus:
gsar @foobar.txt poppins.txt

If response files are needed, most Unix shells will allow
gsar `cat foobar.txt` poppins.txt

-r\[string]
String which is to replace search string in file. Use -r
to delete the search string from the file i.e. replace
with nothing. Ctrl characters can be entered in the same
way as in the search string. If this option is left out,
gsar only performs a search. The string must follow
directly after r.

-i
Ignore case difference when comparing strings. I.e. foo-
bar matches fooBAR.

-B
Just display the search & replace buffers, for test pur-
poses.

-f
If the output file already exists this switch can be used
to force an overwrite of the existing output file.

-o
Search and replace of multiple files, overwrite the input
file(s). For each input file, gsar creates a tempfile
which contains the replacements and copies the tempfile to
the original input file name. If no matches were found,
the input file stays the same. The tempfile is removed.

Example:
gsar -s__ZTC__ -r__TURBOC__ -o foo.c bar.c bat.c
The files foo.c, bar.c & bat.c are all changed.

-c\[n]
Display the context around a match in a textual manner.
Undisplayable characters are displayed as a dot (`.'). n
is optional number of bytes in context. n must follow
directly after c.

-x\[n]
Display the context around a match as a hexadecimal dump.
Undisplayable characters are displayed as a dot (`.'). n
is optional number of bytes in context. n must follow
directly after x.

-b
Display the byte offset of the match in hex.

-l
Only list filename and number of matches if any (default).

-h
Suppress display of filename when displaying context or
byte offsets.

-du
Convert a DOS ASCII file to UNIX (strips carriage return).

-ud
Convert a UNIX ASCII file to DOS (adds carriage return).

-F
Filter mode, gsar takes it's input from stdin and redi-
rects eventual output to stdout. All error messages are
sent stderr.

-G
Display the GNU General Public Licence.


Examples
Search for two spaces at the end of a line (DOS text) and
replace with just a carriage return overwriting the origi-
nal files:

gsar -s:x20:x20:x0d -r:x0d -o foobar.txt *.c

Convert a UNIX text file to DOS format overwriting the
original file:

gsar -ud -o unix.txt

Search for the string WATCOM and replace with __ZTC__
using gsar as a filter. Output is redirected to a new
file:

gsar -sWATCOM -r__ZTC__ -F foo_z.c

Display textual context of the string error in the file
gsar.exe disregarding case. With 40 bytes in the context:

gsar -serror -i -c40 gsar.exe

Search for the string gnu in the file fsf and replace it
with wildebeest, creating a new output file africa:

gsar -sgnu -rwildebeest fsf africa

(if the file africa exists, you have to use the -f option
to overwrite it.)

Search for the string error in the file command.com and
display the byte offset of each match:

gsar -serror -b command.com


Limitations
No wildcards or regular expressions allowed in search
string.

On MSDOS platforms stdin from a tty is not allowed because
stdin has been turned into binary. MSDOS will not catch
the Ctrl-Z signifying EOF.

Authors
Tormod Tjaberg (coding, design (all bugs are his))
Hans Peter Verne (ideas, demands, testing, UNIX platforms)

If you have any comments, bug reports or whatever, we can
be reached through email at:

tjaberg@online.no
hpv@kjemi.uio.no[/quote]

Cheers and Regards

Edited by bphlpt
0

Share this post


Link to post
Share on other sites

@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]
"

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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

split_inf_7.7z

changelog.txt

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

Here is the final version: split_inf_8.7z

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:

:SPLITINF
SETLOCAL ENABLEDELAYEDEXPANSION
SET WORK=%~f1
SET SPLITDIR=%~dp1SPLIT_%~n1

::copy the source
REM COPY /B %Source% %Work%

::pre-process the work copy of source

::add a leading space before ANY line
CALL :run_gsar :x0d:x0a :x0d:x0a:x20

::remove any line containing only a space
CALL :run_gsar :x0d:x0a:x20:x0d:x0a :x0d:x0a:x0d:x0a

::Problem:
::this leaves a line containing a single space an the end of the file with NO CR+LF

::Solution part 1:
::ECHO a signature:
ECHO mod by jaclaz>>%Work%


::run Many
:gsar_loop
SET Loop_Flag=0

::Remove any empty line (just CR+LF)
CALL :run_gsar :x0d:x0a:x0d:x0a :x0d:x0a

::Remove any [TAB] and replace with single space
CALL :run_gsar :x09 :x20

::Remove any space before a CR+LF
CALL :run_gsar :x20:x0d:x0a :x0d:x0a

::Normalize begin of line with no space
CALL :run_gsar :x0d:x0a:x20 :x0d:x0a

::normalize "=" with no spaces on side
CALL :run_gsar :x20:x3d :x3d
CALL :run_gsar :x3d:x20 :x3d

::Remove spaces before Sections
CALL :run_gsar :x0d:x0a:x20:x5b :x0d:x0a:x5b

IF NOT !Loop_Flag!==0 GOTO :gsar_loop

::Final adjustments to be run ONLY once
::run Once
::Replace "==" with a dummy string "}#}"
CALL :run_gsar :x3d:x3d :x7b:x23:x7b

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

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

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

::Replace stoopid "&" with a dummy string "}##}"
CALL :run_gsar :x26 :x7b:x23:x23:x7b

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

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

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

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

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

::Rejoin double-lined strings
CALL :run_gsar :x5C:x0D:x0A

::Solution part 2:
::Remove signature
CALL :run_gsar :x20:x6D:x6F:x64:x20:x62:x79:x20:x6A:x61:x63:x6C:x61:x7A:x0d:x0a :x0d:x0a
::Remove signature even if original had no CR+LF and thus signature was appended to entry
CALL :run_gsar :x6D:x6F:x64:x20:x62:x79:x20:x6A:x61:x63:x6C:x61:x7A:x0d:x0a :x0d:x0a

RD/Q/S !SPLITDIR! >NUL 2>&1
MD !SPLITDIR!
FOR /F "tokens=* delims=" %%I IN ('FINDSTR/B "[" !WORK!') DO IF NOT EXIST "!SPLITDIR!\%%I.inf" (
ECHO>>"!SPLITDIR!\[1ndex].inf" %%I
ECHO>>"!SPLITDIR!\%%I.inf" %%I
)
FOR /F "tokens=* delims= eol=€" %%I IN (!WORK!) DO (
SET SECTION=0
IF NOT "%%I"=="*" IF EXIST "!SPLITDIR!\%%I.inf" (
SET SECTION=1
SET SECTIONFILE=%%I
) ELSE (
SET SECTION=0
)
IF !SECTION!==0 ECHO %%I>>"!SPLITDIR!\!SECTIONFILE!.inf"
)

GOTO :EOF


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

GOTO :EOF


:EOF

Second part:

:JOININF
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!

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

::Add two CR+LF before each Section - a section has a CR+LF before
CALL :run_gsar :x0d:x0a:x5b :x0d:x0a:x0d:x0a:x0d:x0a:x5b

::Restore changes made to make the .inf "batch compatible"

::Replace dummy string "}#}" with "=="
CALL :run_gsar :x7b:x23:x7b :x3d:x3d

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

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

::Replace even more stoopid "}##########}" with a dummy string "kbid="
CALL :run_gsar :x7b:x23:x23:x23:x23:x23:x23:x23:x23:x23:x23:x7b :x69:x64:x3d


::Replace dummy string "}##}" with stoopid "&"
CALL :run_gsar :x7b:x23:x23:x7b :x26

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

::Replace dummy string "}####}" with a "<"
CALL :run_gsar :x7b:x23:x23:x23:x23:x7b :x3c

::Replace dummy string "}#####}" with a ">"
CALL :run_gsar :x7b:x23:x23:x23:x23:x23:x7b :x3e

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

::Remove first two CR+LF's, the ones before "[Version]"
CALL :run_gsar :x0d:x0a:x0d:x0a:x5B:x56:x65:x72:x73:x69:x6F:x6E:x5D :x5B:x56:x65:x72:x73:x69:x6F:x6E:x5D

::Replace dummy string "}#########}" with even more stoopid "|"
CALL :run_gsar :x7b:x23:x23:x23:x23:x23:x23:x23:x23:x23:x7b :x7c

::remove a leading space before ANY line
CALL :run_gsar :x0d:x0a:x20 :x0d:x0a

GOTO :EOF


:EOF

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
0

Share this post


Link to post
Share on other sites

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"

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.