Re: OT: help with a text file



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 assume
a 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

.



Relevant Pages

  • Re: finding duplicated files
    ... duplicates and rems out the delete command for the first duplicate in each set. ... echo Purpose: Deletes identical files using multiple checksums from FSUM ... goto:EOF ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Deleting accounts and folders
    ... if ==@echo Syntax: DelUser UserName&goto:EOF ... if /i "%user%" NEQ "%usr%" goto notfound ...
    (microsoft.public.win2000.general)
  • Re: Network File Audit/Scanning
    ... echo Checking %1 ... if exist c:\Audited\%1.txt goto:eof ... you all PCs that have the file you're looking for. ...
    (microsoft.public.windows.file_system)
  • Re: Network File Audit/Scanning
    ... echo Checking %1 ... if exist c:\Audited\%1.txt goto:eof ... you all PCs that have the file you're looking for. ...
    (microsoft.public.windows.file_system)
  • Re: Searching Within a Text File
    ... Steve Seguis schrieb: ... > goto:EOF ... @echo off&setlocal EnableDelayedExpansion ...
    (microsoft.public.scripting.vbscript)