-1

I have a file having following contents -

SF:D:\Saurabh\Work\WS\devicehowto.war\scripts\.\Greeter.js
DA:1,2
DA:4,2
DA:5,2
end_of_record
SF:D:\Saurabh\Work\WS\devicehowto.war\scripts\.\GreeterTest.js
DA:1,2
DA:3,2
DA:4,2
end_of_record

I need a batch script to replace all occurrence of "D:\Saurabh\Work\WS\devicehowto.war\scripts.\" with space character. So, after running the batch script the content should look like -

SF:Greeter.js
    DA:1,2
    DA:4,2
    DA:5,2
    end_of_record
    SF:GreeterTest.js
    DA:1,2
    DA:3,2
    DA:4,2
    end_of_record

Please help. Thanks.

Saurabh
  • 2,384
  • 6
  • 37
  • 52
  • These answers might be helpful: http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir – Anders Lindahl Jun 07 '13 at 07:50

2 Answers2

2
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
(
FOR /f "delims=" %%i IN (saurabh.txt) DO (
 SET "line=%%i"
 SET "line=!line:D:\Saurabh\Work\WS\devicehowto.war\scripts\.\=!"
 ECHO(!line!
)
)>new.txt
TYPE new.txt
GOTO :eof

producing new.txt.

Not sure why the second and successive lines are indented. If this is deliberate, please specify criteria.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Thanks a lot Peter. This is working fine. Just one thing. Can we update same file instead of writing output in new.txt? – Saurabh Jun 07 '13 at 08:46
  • 1
    Not in-place. simply `move /y new.txt saurabh.txt` where the `type` is. – Magoo Jun 07 '13 at 08:51
1

good job for sed

sed "/SF/s/:.*\\/:/" saurabh.txt
Endoro
  • 37,015
  • 8
  • 50
  • 63