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

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.
  • Comment on Re^2: Inplace editing, one liner, without a backup file?

Replies are listed 'Best First'.
Re^3: Inplace editing, one liner, without a backup file?
by ikegami (Patriarch) on Aug 09, 2005 at 13:31 UTC

    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>