#73238 - 2003-02-19 09:10 AM
need script
|
barjoe
Lurker
Registered: 2003-02-19
Posts: 2
|
Has someone a script who search a word in a file and replace it by an other
Please help me, thanks
|
|
Top
|
|
|
|
#73240 - 2003-02-19 09:46 AM
Re: need script
|
barjoe
Lurker
Registered: 2003-02-19
Posts: 2
|
it is the hosts file
|
|
Top
|
|
|
|
#73241 - 2003-02-19 09:50 AM
Re: need script
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
from the scratch :
break on
dim $x $file = @scriptdir + "\test.txt" $search = "phrase to replace" $replace = "phrase to insert" $FileStr = ""
$ = open(1,$file,2) if not @error $x = readline(1) while not @error if instr($x,$search) $FileStr = $FileStr + join(split($x,$search),$replace) + @crlf else $FileStr = $FileStr + $x + @crlf endif $x = readline(1) loop $ = close(1) del $file $ = open(1,$file,5) $ = writeline(1,$FileStr) $ = close(1) ? "File has been adapted" ? else ? "file open failed : " + @serror ? endif
? "Hit any key to quit ..."
get $
This replaces (if present) $Search by $replace
Possible problem : it adds an additional @crlf at the end (Ok ... tested with my host file and it adds the additional crlf only if there is none in the original, speak, it adds only once ! Hehe : changed by this all entries called daimlerchrysler.com to chryslerdaimler.com and back This scriplet has evil powers if used in a loop to modify remote files )
hth Jochen [ 19. February 2003, 11:35: Message edited by: jpols ]
_________________________
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 302 anonymous users online.
|
|
|