MSFN Forum: Insert (append) text into existing .inf file - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Insert (append) text into existing .inf file batch file request to do it unattended Rate Topic: -----

#1 User is offline   Bilou_Gateux 

  • Powered by Windows Embedded
  • PipPipPipPipPip
  • Group: Members
  • Posts: 766
  • Joined: 03-January 04

Posted 31 October 2005 - 12:58 PM

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?

This post has been edited by Bilou_Gateux: 12 February 2006 - 07:53 AM



#2 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,117
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 31 October 2005 - 04:37 PM

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

#3 User is offline   Bilou_Gateux 

  • Powered by Windows Embedded
  • PipPipPipPipPip
  • Group: Members
  • Posts: 766
  • Joined: 03-January 04

Posted 01 November 2005 - 01:31 AM

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.

Quote

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

This post has been edited by Bilou_Gateux: 12 February 2006 - 09:27 AM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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



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