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

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.