ini - Batch file for replacing text, or writing it if it's not there -
good morning,
i'm having issue trying figure out how approach project i'm working on...
basically what's happening i'm needing go text file, string of text, (i.e. columnseparator=y) , changing columnseparator=n.
if "columnseparator=y/n" doesn't exist, need write ~4-5 lines of text add section of text file. appending fine.
now, tricky part. file i'm editing, configuration file program used on ~850 machines, , every file little different, , depending on window xp vs windows 7, located in 2 different places.
in windows 7 it's located in: c:\as400\s10138fd.ws
in windows xp it's located in: c:\program files\ibm\client access\emulator\private\as400.ws
any ideas??
thanks!!
here *.ws file information need edit:
[profile] id=ws description= version=9 [translation] ibmdefaultview=y defaultview= ibmdefaultdbcs=y defaultdbcs= [communication] autoconnect=y link=telnet5250 session=5250 forceconfigpanel=n [telnet5250] hostname=s10138fd security=y hostportnumber=992 sslclientauthentication=y certselection=autoselect autoreconnect=y [5250] hostcodepage=037-u printertype=ibm3812 [keyboard] cuakeyboard=2 language=united-states ibmdefaultkeyboard=n defaultkeyboard=c:\as400\as400.kmp [lastexitview] a=4 1335 -14 896 609 3 13 29 400 0 ibm3270� 37
i need add:
[window] viewflags=ce00 rulelinepos=0 0 columnseparator=n
here new script:
if exist "c:\as400\s10138fd.ws" (cd \as400) copy s10138fd.ws temp.ws echo [window]>s10138fd.ws echo viewflags=ce00>>s10138fd.ws echo rulelinepos=0 0>>s10138fd.ws echo columnseparator=n>>s10138fd.ws type temp.ws >>s10138fd.ws del temp.ws ) else (cd\program files\ibm\client access\emulator\private) copy as400.ws temp.ws echo [window]>as400.ws echo viewflags=ce00>>as400.ws echo rulelinepos=0 0>>as400.ws echo columnseparator=n>>as400.ws type temp.ws >>as400.ws del temp.ws ) pause
if understand correctly, don't need know original value of columnseparator, reset n.
use following code save copy of config file without columnseparator data, configfile config file:
type configfile | find /v "columnseparator" > configfile.tmp
then use simple echo , redirect append columnseparator value end of file.
echo columnseparator=n >> configfile.tmp
you can delete old config file, , rename newly created 1 (configfile.tmp) replace old one...
here updated script:
type configfile | find /v "[window]" | find /v "viewflags" | find /v "rulelinepos" | find /v "columnseparator">configfile.tmp echo [window]>>configfile.tmp echo viewflags=ce00>>configfile.tmp echo rulelinepos=0 0>>configfile.tmp echo columnseparator=n>>configfile.tmp
that should work, though needs in script find desired config file. find /v
command filters out line include desired string.
again updated... (again)
@echo off setlocal enabledelayedexpansion systeminfo | find "os name">temp.tmp %%a in ('findstr "7" temp.tmp') set ver=7 if "%ver%" == "7" ( set file=s10138fd.ws set path=c:\as400\ ) %%a in ('findstr "xp" temp.tmp') set ver=xp if "%ver%" == "xp" ( set file=as400.ws set path=c:\program files\ibm\client access\emulator\private\ ) del temp.tmp goto find :find if not exist "%path%%file%" ( echo config file not exist! goto end ) echo config file exists! echo proceeding fix... goto dumper :dumper cd "%path%" type %file% | find /v "[window]" | find /v "viewflags" | find /v "rulelinepos" | find /v "columnseparator">configfile.tmp echo [window]>>configfile.tmp echo viewflags=ce00>>configfile.tmp echo rulelinepos=00>>configfile.tmp echo columnseparator=n>>configfile.tmp ren %file% %file%.bk ren configfile.tmp %file% echo fixed! goto end :end exit
Comments
Post a Comment