Re: OT: help with a text file
- From: Robert Roland <fake@xxxxxxxxx>
- Date: Wed, 13 Aug 2008 14:37:51 +0200
On Tue, 12 Aug 2008 13:28:26 -0700 (PDT), a7yvm109gf5d1@xxxxxxxxxxx
wrote:
Here's the deal, I wish to change a line to something else inside a
pure text file, while leaving the other lines unmolested.
So something that reads the file line by line, if the line doesn't
match my criteria dump the line as is into a new file, if it matches,
substitute my new line, do so until the end of the file.
From your headers, it looks like you are running Windows, so I assumea Windows solution would be OK.
Do you want to replace the entire line if part of it exists, or do you
simply want to replace some text with some other text? If the latter,
a few lines of batch should be sufficient:
@echo off
setlocal
del outputfile.txt
for /F "delims=" %%n in (inputfile.txt) do call :fixline %%n
goto :EOF
:fixline
set line=%*
set line=%line:lookfor=replacewith%
echo %line%>>outputfile.txt
goto :EOF
If your search strings contain special characters, you may run into
trouble. In that case, I'd recommend a VBScript in stead. It's
slightly more complicated than batch, but much more powerful and
robust. If speed is an issue, I'd also recommend VBScript.
--
RoRo
.
- Follow-Ups:
- Re: OT: help with a text file
- From: MooseFET
- Re: OT: help with a text file
- Prev by Date: Re: OT: interesting global warming quote found elsewhwere
- Next by Date: Re: OT: interesting global warming quote found elsewhwere
- Previous by thread: Re: OT: help with a text file
- Next by thread: Re: OT: help with a text file
- Index(es):
Relevant Pages
|