Page 1 of 1

Delete everything in txt after fifth slash

Posted: 31 Oct 2018 10:18
by Tami
Hi,
I wanted to know if someone could help me with this.
The batch file should delete everything in the line in the .txt file after the fifth slash, how could I do this? I don't have a clue where to start with this :?

Example of a .txt file:
Before:

Code: Select all

http://www.website.net/sr/PD2QPVGPRH2/?NameOfTheFile_05_720p.rar
http://www.website.net/sr/SWLYPVGPRNV/?NameOfTheFile_05_1080p.part1.rar
http://www.website.net/sr/23IXPVGPWXFO/?NameOfTheFile_05_1080p.part2.rar
http://www.website.net/sr/15ZPPVGPTN/?NameOfTheFile_06_720p.rar
http://www.website.net/sr/F6KXPVGPIYXO/?NameOfTheFile_06_1080p.part1.rar
http://www.website.net/sr/U79WPVGPLDM/?NameOfTheFile_06_1080p.part2.rar
http://www.website.net/sr/P8PPPVGPB4/?NameOfTheFile_07_720p.rar
Afterwards:

Code: Select all

http://www.website.net/sr/PD2QPVGPRH2/
http://www.website.net/sr/SWLYPVGPRNV/
http://www.website.net/sr/23IXPVGPWXFO/
http://www.website.net/sr/15ZPPVGPTN/
http://www.website.net/sr/F6KXPVGPIYXO/
http://www.website.net/sr/U79WPVGPLDM/
http://www.website.net/sr/P8PPPVGPB4/
Thanks in advance! ^^

Re: Delete everything in txt after fifth slash

Posted: 31 Oct 2018 12:21
by Squashman
Two options for you in this code. Use the question mark as the delimter or use the forward slash as the delimiter.

Code: Select all

@echo off
FOR /F "tokens=1 delims=?" %%G IN (a.txt) do echo %%G
echo ----------------------------------------------
FOR /F "tokens=1-4 delims=/" %%G IN (a.txt) do echo %%G//%%H/%%I/%%J/
Output

Code: Select all

http://www.website.net/sr/PD2QPVGPRH2/
http://www.website.net/sr/SWLYPVGPRNV/
http://www.website.net/sr/23IXPVGPWXFO/
http://www.website.net/sr/15ZPPVGPTN/
http://www.website.net/sr/F6KXPVGPIYXO/
http://www.website.net/sr/U79WPVGPLDM/
http://www.website.net/sr/P8PPPVGPB4/
----------------------------------------------
http://www.website.net/sr/PD2QPVGPRH2/
http://www.website.net/sr/SWLYPVGPRNV/
http://www.website.net/sr/23IXPVGPWXFO/
http://www.website.net/sr/15ZPPVGPTN/
http://www.website.net/sr/F6KXPVGPIYXO/
http://www.website.net/sr/U79WPVGPLDM/
http://www.website.net/sr/P8PPPVGPB4/

Re: Delete everything in txt after fifth slash

Posted: 31 Oct 2018 15:30
by Tami
Worked perfectly, thanks for your help, love you <3