Jump to content

Insert (append) text into existing .inf file


Recommended Posts

I have parsed with HIVEUPD.CMD some lines from a lot of KB######.INF files of Microsoft Critical updates and output the result in two files: HIVESFT.TXT and HIVECLS.TXT

i would like to insert hivesft.txt into %source%\i386\HIVESFT.INF at end of [AddReg] section:

just before next section called [AddReg.Upgrade]

i would like to insert hivecls.txt into %source%\i386\HIVECLS.INF at end of [AddReg] section:

just before next section called [DelReg]

could it be done with a batch?

Edited by Bilou_Gateux
Link to comment
Share on other sites


Yes it can be done with a batch file and no third party utilities, however it will not necessarily be quick, and the coding isn't nice.

The ideal tool would be SED or AWK (GAWK), both of which should be available here, for your pupose, however can you not use Fedit, (search the forum for it).

Link to comment
Share on other sites

Doing it with FEdit is too complex:

Editing text file from batch file

I have already used SED for appending lines to an existing inf as posted here

in this old archived post, i was adding new lines one by one.

SED allows to insert a block of lines before defined pattern with one command:

for updating HIVESFT.INF, i will add this 1st line to HIVESFT.TXT: /[AddReg.Upgrade]/ i

for updating HIVECLS.INF, i will add this 1st line to HIVECLS.TXT: /[DelReg]/ i

add backslash \ at end of each line to be inserted (including the 1st).

special metacharacters like backslash \ or quote " need to be escaped with an added backslash \

left [ and right ] square brackets are escaped with an added backslash \

Finally i will use gsar.exe which is exactly the needed tool.

:// use charmap to find character hex code

:// search 'reverse solidus' and escape with 'reverse solidus'

gsar -s:x5c -r:x5c:x5c -o temp\hivecls.txt

:// search 'quotation mark' and escape with 'reverse solidus'

gsar -s:x22 -r:x5c:x22 -o temp\hivecls.txt

:// search 'carriage return' and add 'reverse solidus' before

gsar -s:x0d -r:x5c:x0d -o temp\hivecls.txt

:// search 4 blanks & 'Capital Letter H' and keep only 'Capital Letter H'

gsar -s:x20:x20:x20:x20:x48 -r:x48 -o temp\hivecls.txt

:// Header

:// search 'left square bracket' and escape with 'reverse solidus'

gsar -s:x5b -r:x5c:x5b -o temp\hivecls.txt

:// search 'right square bracket' and escape with 'reverse solidus'

gsar -s:x5d -r:x5c:x5d -o temp\hivecls.txt

:// sed don't support direct alteration of input files so output to intermediate file

sed -f temp\hivecls.txt i386\hivecls.inf >temp\hivecls.int

:// replace original hivecls.inf with intermediate file hivecls.int

copy /y temp\hivecls.int i386\hivecls.inf

Edited by Bilou_Gateux
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...