0
votes

I'm having trouble creating a batch file that takes a file file.txt and removes the text after a delimiter and creates a new file with the changes.

Ex:

file.txt would contain:

ashlasfj/asdkasdkj/asdkjasd
jhsdkfjhsdf/ajhsjduias/asjhfhsd

the newfile.txt would keep everything prior to the first /:

ashlasfj
jhsdkfjhsdf

I was thinking of using a for loop:

for /f "tokens=1,* delims=/" %%A in (test.txt) do ( something here )

1
What OS is this for? Since you're saying "batch" I assume it's Windows, but you need to make that clear. - lurker
Sorry the <br> wasn't supposed to be there. - Brian

1 Answers

1
votes

Try this:

@echo off
setlocal

for /f "tokens=1 delims=/" %%a in (test.txt) do (echo %%a >> newfile.txt)