Jump to content

How to merge two text files?


Recommended Posts

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
Link to comment
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]
"

Link to comment
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

Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
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

Link to comment
Share on other sites

  • 4 weeks later...

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
Link to comment
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"

Link to comment
Share on other sites

  • 4 weeks later...

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?

Link to comment
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

Link to comment
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 ;)).

Link to comment
Share on other sites

  • 2 months later...

There are two files:

1.txt

[SourceFileInfo]
clusapi.dll=B95AC82B54FE4359C3453264F848509A,0005000008931AA8,55568

2.txt

[SourceFileInfo]
clusnet.sys=A0610690266ED57A2D04EA5D7EC8084C,0005000008931AA8,67760

If I do "copy 1.txt+2.txt 3.txt" I get this:

[SourceFileInfo]
clusapi.dll=B95AC82B54FE4359C3453264F848509A,0005000008931AA8,55568
[SourceFileInfo]
clusnet.sys=A0610690266ED57A2D04EA5D7EC8084C,0005000008931AA8,67760

but I would like to get something similar to this:

[SourceFileInfo]
clusapi.dll=B95AC82B54FE4359C3453264F848509A,0005000008931AA8,55568
clusnet.sys=A0610690266ED57A2D04EA5D7EC8084C,0005000008931AA8,67760

Is it possible?

In C# you can do it programmatically . Read those file one by one and store it ino a string and finally write the string to a single file.

string line = null;

System.IO.TextReader readFile = new StreamReader("filename.txt");

line = line + readFile.ReadToEnd();

read three files

and write file

write file

System.IO.TextWriter writeFile = new StreamWriter("filename.txt");

writeFile.WriteLine("line");

check this link.

http://csharp.net-informations.com/file/csharp-textwriter.htm

wills.

Link to comment
Share on other sites

  • 4 months later...

Using COPY /B serves no purpose when used in that manner, in fact it is the default mode when copying single files.

Something is different between 2K and XP in this matter.

When I do:

COPY/B NUL 1.txt

an empty file gets created when using cmd.exe from Windowx XP but when doing the same with Windows 2000's cmd.exe:

The parameter is incorrect

and no file is created.

In Windows 2000 it's necessary to use:

COPY NUL 1.txt

to create an empty file while in XP the switch doesn't matter.

Link to comment
Share on other sites

  • 3 weeks later...

I'm trying to divide and then relink registry entries like this one...

1.txt

HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink",,0x10000, "MSGOTHIC.TTC,MS UI Gothic"

into


HKLM
"SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink"

0x10000
"MSGOTHIC.TTC,MS UI Gothic"

I've come up with this script:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
set tokens=
CD.>temp.txt
:TEST
SET/A tokens+=1
FOR /F "delims=" %%A IN (1.txt) DO (
FOR /F "tokens=%tokens% delims=," %%B IN ("%%A") DO (
FOR /F "tokens=1* delims= " %%C IN ("a %%B") DO (
SET STRING=
ECHO %%D|FINDSTR/V ^"^"^" >NUL && SET STRING=%%D
IF NOT DEFINED STRING ECHO %%D|FINDSTR/B ^"^"^"|FINDSTR/E ^"^"^" >NUL && SET STRING=%%D
IF NOT DEFINED STRING ECHO %%D|FINDSTR/B ^"^"^" >NUL && SET STRING1=%%D
IF NOT DEFINED STRING ECHO %%D|FINDSTR/E ^"^"^" >NUL && SET STRING2=%%D
IF DEFINED STRING (
ECHO>>temp.txt !STRING!
) ELSE (
IF DEFINED STRING1 IF DEFINED STRING2 (
ECHO>>temp.txt !STRING1!,!STRING2!
SET STRING1=
SET STRING2=
)
)
GOTO :TEST
)
)
FOR /F "delims=" %%A IN (temp.txt) DO <NUL SET/P="%%A,">>2.txt
)

The result is:

2.txt

HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink",0x10000,"MSGOTHIC.TTC,MS UI Gothic",

I know it's not pretty and I need to work on it more but the biggest problem here is that the FOR /F loop:

FOR /F "tokens=%tokens% delims=," %%B IN ("%%A") DO (

done on

HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink",,0x10000, "MSGOTHIC.TTC,MS UI Gothic"

makes the empty token before "0x10000" disappear. I've done some Googling but couldn't really find any simple solution to this default behaviour of FOR /F. Is there simple way to preserve it other than using gsar before running the script to replace ",," with something else like ","","? :rolleyes:

Edited by tomasz86
Link to comment
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.
×
×
  • Create New...