I have a file which has entries as below.
/a/b/c/d/e/f
/a/b/c/g/k/l/f/j/h
/a/b/c/i/m/n/p
I need a command in Windows which would remove the '/a/b/c'
part from the file.
The output file should look like
d/e/f
g/k/l/f/j/h
i/m/n/p
I tried using the for
command with /
as the delimiter, but I couldn't get the expected result.
How can I do this?
@echo off
(for /f "tokens=3,* delims=/" %%a in (input.txt) do echo %%b) > output.txt
And the "trick" is to ask for the third token and the rest of the line.
To use it directly from the command line:
(for /f "tokens=3,* delims=/" %a in (input.txt) do @echo %b) > output.txt
The escaped percent signs are simplified and, as from command line the echo off
is not enabled by default, the @
before echo
is needed.
PowerShell:
get-content test.txt | foreach-object {
$_ -replace '/a/b/c/',''
} | out-file test2.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With