Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows batch script: substring calculation

I have a situation like this. I have a list of urls in a file.

SET str1="http://www.domain.com/dir1/dir2/dir3/dir4/dir5/file1.txt"

In the above string http://www.domain.com/dir1/dir2/dir3 is constant in all the urls. I need to extract the rest of the path in each url.

I mean, i need to get the final string from the above url is /dir4/dir5/file1.txt

Thanks

like image 570
Mohamed Saligh Avatar asked Jun 08 '11 06:06

Mohamed Saligh


Video Answer


1 Answers

You need the %var:~start,end% notation. For example, if you run this:

@SET str1="http://www.domain.com/dir1/dir2/dir3/dir4/dir5/file1.txt"
@ECHO %str1:~37,-1%

It will print /dir4/dir5/file1.txt.

like image 60
Gabe Avatar answered Sep 22 '22 17:09

Gabe