Delete everything in txt after fifth slash

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Tami
Posts: 10
Joined: 31 Mar 2017 11:01

Delete everything in txt after fifth slash

#1 Post by Tami » 31 Oct 2018 10:18

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! ^^

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Delete everything in txt after fifth slash

#2 Post by Squashman » 31 Oct 2018 12:21

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/

Tami
Posts: 10
Joined: 31 Mar 2017 11:01

Re: Delete everything in txt after fifth slash

#3 Post by Tami » 31 Oct 2018 15:30

Worked perfectly, thanks for your help, love you <3

Post Reply