qwe001
qwe001

Reputation: 633

How to trim string in command prompt?

I have a lot of shortcut urls in a directory.

C:\Users\Owner\Desktop\ReadItLaters>dir *.url /b
aaa.url
bbb.url
ccc.url

...

zzz.url

I want to pickup those url. so I wrote command like this.

for %i in (*.url) do @type "%i" | find "URL=" 

that outputs like this.

URL=https://www.example.com/aaa.html
URL=https://www.example.com/bbb.html
URL=https://www.example.com/ccc.html

...

URL=https://www.example.com/zzz.html

It tastes nice. but I want to get url strings WITHOUT "URL=".

I wish to output like this.

https://www.example.com/aaa.html
https://www.example.com/bbb.html
https://www.example.com/ccc.html

...

https://www.example.com/zzz.html

How can I replace "URL=" to empty?

Upvotes: 2

Views: 8252

Answers (3)

Io-oI
Io-oI

Reputation: 2565

You can use substring, skipping the first 4 characters in your string: %_url:~4%

/

for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:~4%

for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:~4%

Upvotes: 3

Compo
Compo

Reputation: 38719

You should be able to get the information for multiple URL files, without the need to nest two for loops. You can take advantage of FindStr's ability to search through multiple files directly.

:

@For /F "Tokens=1*Delims==" %%G In ('""%__AppDir__%findstr.exe" /IR "^URL=http" "*.url" 2>NUL"')Do @Echo %%H

:

For /F "Tokens=1*Delims==" %G In ('""%__AppDir__%findstr.exe" /IR "^URL=http" "*.url" 2>NUL"')Do @Echo %H

Upvotes: 0

Stephan
Stephan

Reputation: 56238

use a for /f loop to process the lines:

for /f "tokens=2 delims==" %%a in ('type *.url 2^>nul^|find "URL="') do @echo %%a

or a bit saver (in case the URLs contain =)

for /f "tokens=1,* delims==" %%a in ('type *.url 2^>nul^|findstr /b "URL="') do @echo %%b

See for /? for details.

(Note: this is batch file syntax. If you want to use it directly on the command line, replace each %% with a single %)

Upvotes: 1

Related Questions