-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,267
  • 4
  • 36
  • 48
  • 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
  • 72,034
  • 7
  • 58
  • 78
1

good job for sed

sed "/SF/s/:.*\\/:/" saurabh.txt
Endoro
  • 35,920
  • 8
  • 49
  • 63