MSFN Forum: How to merge two text files? - MSFN Forum

Jump to content


  • 12 Pages +
  • « First
  • 7
  • 8
  • 9
  • 10
  • 11
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

How to merge two text files? and sort them... Rate Topic: -----

#161 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 23 April 2012 - 06:24 AM

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.

This post has been edited by tomasz86: 23 April 2012 - 06:26 AM



#162 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,409
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 23 April 2012 - 10:51 AM

View Posttomasz86, on 23 April 2012 - 06:24 AM, said:

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 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 24 April 2012 - 08:32 AM

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.

This post has been edited by tomasz86: 24 April 2012 - 09:48 AM


#164 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 22 May 2012 - 09:50 AM

View Postjaclaz, on 21 April 2012 - 01:00 PM, said:

The:

Quote

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


#165 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,409
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 22 May 2012 - 10:23 AM

View Posttomasz86, on 22 May 2012 - 09:50 AM, said:

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 User is online   bphlpt 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,075
  • Joined: 12-May 07

Posted 23 May 2012 - 04:18 AM

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

Spoiler


Cheers and Regards

This post has been edited by bphlpt: 23 May 2012 - 04:21 AM


#167 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 24 May 2012 - 06:19 PM

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


#168 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,409
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 25 May 2012 - 09:42 AM

View Posttomasz86, on 24 May 2012 - 06:19 PM, said:

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 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 26 June 2012 - 02:31 AM

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 File(s)


This post has been edited by tomasz86: 26 June 2012 - 02:50 AM


#170 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,409
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 26 June 2012 - 03:28 AM

View Posttomasz86, on 26 June 2012 - 02:31 AM, said:


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.

View Posttomasz86, on 26 June 2012 - 02:31 AM, said:

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 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 18 July 2012 - 06:53 PM

Here is the final version: Attached File  split_inf_8.7z (3.28K)
Number of downloads: 7

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!

This post has been edited by tomasz86: 18 July 2012 - 07:45 PM


#172 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 19 July 2012 - 09:13 PM

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"


#173 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 11 August 2012 - 10:31 AM

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?

#174 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,409
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 11 August 2012 - 10:44 AM

View Posttomasz86, on 11 August 2012 - 10:31 AM, said:

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 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 11 August 2012 - 10:56 AM

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

#176 User is offline   willsmannar 

  • Group: Members
  • Posts: 1
  • Joined: 19-October 12
  • OS:Vista Ultimate x86
  • Country: Country Flag

Posted 19 October 2012 - 11:38 AM

View Posttomasz86, on 08 June 2011 - 12:53 AM, said:

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-in...-textwriter.htm

wills.

#177 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 02 March 2013 - 09:12 PM

View PostYzöwl, on 31 July 2011 - 10:55 AM, said:

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.

#178 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,409
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 03 March 2013 - 05:47 AM

For the record:
http://www.robvander...com/useless.php

Quote

Create Empty Files

to create an empty (zero bytes) file I always used:
TYPE NUL > new_empty_file_name

Robert Van Etta showed me an even shorter command:
CD.> new_empty_file_name


jaclaz

#179 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 04 March 2013 - 03:45 AM

Thanks :)

The short one

CD.> new_empty_file_name

is really nice.

#180 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 25 March 2013 - 06:02 AM

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:

This post has been edited by tomasz86: 25 March 2013 - 06:05 AM


Share this topic:


  • 12 Pages +
  • « First
  • 7
  • 8
  • 9
  • 10
  • 11
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy