in reply to Inplace editing, dos one liner, without a backup file?

if for some reason it's now * vs *.* that's the problem, or you can't just del *.bak at the end due to size constraints, you can loop in a batch file, working with one file at a time so there's never more than 1 .bak file present (the self-calling is because the FOR/DO only allows for running a single command):
REM foo.bat @echo OFF IF "%1" == "process" GOTO processFile GOTO convertAll :convertALL FOR %%f IN (c:\temp\*.txt) DO CALL %0 process "%%f" GOTO end :processFile SET in=%2 perl -p -i -e "s/change this/to this/g" %in% del %in%.bak GOTO end :end
Update: Oops. fixed the error in variable name in ":processFile" .. also took advantage of "%0" .. thanks ikegami!

Replies are listed 'Best First'.
Re^2: Inplace editing, one liner, without a backup file?
by tphyahoo (Vicar) on Aug 09, 2005 at 13:02 UTC
    Seems extremely useful (more for the multi file replace than for the deletion of the bak files), but when I run it it just hangs.

      He made a small error. He was using %f% where he needed to use %in%. ...or simply %2. Also, I changed foo.bat to %0.

      @echo off IF "%1" == "process" GOTO processFile GOTO convertAll :convertALL FOR %%f IN (c:\temp\*.txt) DO CALL %0 process "%%f" GOTO end :processFile perl -p -i.bak -e "s/change this/to this/g" %2 del %2.bak GOTO end :end

      If you really wanted to name the parameter, try the following. It cleans up the environment as a bonus (by spawning another shell where CALL was formerly used).

      @echo off IF "%1" == "process" GOTO processFile GOTO convertAll :convertALL FOR %%f IN (c:\temp\*.txt) DO cmd /c %0 process "%%f" GOTO end :processFile SET IN=%2 perl -p -i.bak -e "s/change this/to this/g" %IN% del %IN%.bak GOTO end :end
      </c>