help removing and replacing string between specified strings

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bars143
Posts: 87
Joined: 01 Sep 2013 20:47

help removing and replacing string between specified strings

#1 Post by bars143 » 29 Sep 2013 00:57

hi to batch experts,

i had fbcmd.bat that display list of URLs but transferring list of URLs by adding "> download-list.txt" to a "fbcmd.bat PPICS =ALL:

Code: Select all

fbcmd.bat PPICS =ALL >download-list.txt


will result :

access denied

but i had to to select all and copy then pasted to a text file so that i can removed all whitespace by bat script and the result is a single line:

Code: Select all

https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/48993_100002535134778_1670419627_n.jpgBrendaFeliscohttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/1117539_100001110710172_164502485_n.jpgMarryRoseFernandezhttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1117011_100004568976251_2070804027_n.jpgRowenaAbaoFrantzv+Ñghttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash1/275744_1516676599_1899887613_n.jpgWellanJoyDelaFuertahttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash1/186138_100000029740705_1019427784_n.jpgJewongHanhttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/41716_100000170020453_4351_n.jpgMercyMadeloHerskovitzhttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1118049_597342734_500448546_n.jpg


but all i know is this code but failed:

Code: Select all

@echo off
setlocal enabledelayedexpansion

:: to remove string(it is a name of users) between strings
:: use  *  as it is a syntax for any number of character
:: replaced any charaters between jgp and https
:: example : jgp*https  to  jpgxxxhttps

set "filename=download-list.txt"
set "tempfile=download-list-new.txt"

for /F "delims=" %%a in (%filename%) do (
set "text=%%a"
set "text=!text:jpg*https=jpgxxxhttps!"
echo !text! >%tempfile%
)
pause


i repeat above * syntax does not work.

and all i want is this final output so that i can use it for downloading through wget.exe:

Code: Select all

https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/48993_100002535134778_1670419627_n.jpg
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/1117539_100001110710172_164502485_n.jpg
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1117011_100004568976251_2070804027_n.jpg


you read above? but not replaced with an xxxx string !
but all i need is above result that remove strings between jgp and https
--above result should not be in one line
--all Urls must be one line each.
--so that using wget.exe for downloading would not be a problems for me.


an answer is highly appreciated.
thanks

Bars

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: help removing and replacing string between specified str

#2 Post by Aacini » 29 Sep 2013 01:57

You may use my FindRepl.bat program to do that. For example:

Code: Select all

> type download-list.txt
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/48993_100002535134778_1670
419627_n.jpgBrendaFeliscohttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/1
117539_100001110710172_164502485_n.jpgMarryRoseFernandezhttps://fbcdn-profile-a.
akamaihd.net/hprofile-ak-ash2/1117011_100004568976251_2070804027_n.jpgRowenaAbao
Frantzv+Ðghttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash1/275744_151667659
9_1899887613_n.jpgWellanJoyDelaFuertahttps://fbcdn-profile-a.akamaihd.net/hprofi
le-ak-ash1/186138_100000029740705_1019427784_n.jpgJewongHanhttps://fbcdn-profile
-a.akamaihd.net/hprofile-ak-prn1/41716_100000170020453_4351_n.jpgMercyMadeloHers
kovitzhttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1118049_597342734_50
0448546_n.jpg

> FindRepl "\.jpg[\w\+Ñ]+https:" "\.jpg\r\nhttps:" < download-list.txt > download-list-new.txt

> type download-list-new.txt
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/48993_100002535134778_1670419627_n.jpg
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/1117539_100001110710172_164502485_n.jpg
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1117011_100004568976251_2070804027_n.jpg
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash1/275744_1516676599_1899887613_n.jpg
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash1/186138_100000029740705_1019427784_n.jpg
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/41716_100000170020453_4351_n.jpg
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1118049_597342734_500448546_n.jpg

You may download FindRepl.bat program from this site

Antonio

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: help removing and replacing string between specified str

#3 Post by bars143 » 29 Sep 2013 02:36

hi Aacini,

it is working great ! ! !

but i wonder where and what is

Code: Select all

from

Code: Select all

"\.jpg[\w\+Ñ]+https:"
come from ?
or i misread that it is listed in your thread?

and i only know is this (when you answer my last thread):

Code: Select all

\w
w...
(\w+)
(\w+).
/$:0
/Q:


anyway a helpful answer is highly appreciated from a newbie like me. :D

Bars

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: help removing and replacing string between specified str

#4 Post by Aacini » 29 Sep 2013 10:07

bars143 wrote:hi Aacini,

it is working great ! ! !

but i wonder where and what is

Code: Select all

from

Code: Select all

"\.jpg[\w\+Ñ]+https:"
come from ?

In a regular expression, "\w" search for "any alphanumeric character or underscore", so "\w+" is the standard way to search for "one or more of such characters". To search your data, I first tried this command:

Code: Select all

FindRepl "\.jpg\w+https:" "\.jpg\r\nhttps:" < download-list.txt

That is, search for a dot "\.", "jpg", one or more alphanumeric characters or underscore, and "https:". I get right results excepting for this one:

Code: Select all

https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1117011_100004568976251_2070804027_n.jpgRowenaAbaoFrantzv+Ñghttps://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash1/275744_1516676599_1899887613_n.jpg

The name "RowenaAbaoFrantzv" is followed by "+Ñ" characters that does NOT match previous regexp, so it is necessary to include them: "\+Ñ", but as part of a set with previous characters: "[\w\+Ñ]" that may be repeated one or more times: "[\w\+Ñ]+". That is it!

I suggest you to read the documentation about regular expressions following the links that appear in FindRepl.bat site.

Antonio

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: help removing and replacing string between specified str

#5 Post by bars143 » 29 Sep 2013 19:33

hi Aacini,

thanks anf got it.
i read your links and also read it related links and some google it too.
its really difficult for a newbie like me but of courses have some times to learn a bit like that.

something in wget.exe does not allowed dowloaded URLs with like of "https://...." but removing "s" using my bat script and this result: "http://...." got working. :)

anyway thanks too much for help !!! 8)

Bars

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: help removing and replacing string between specified str

#6 Post by Aacini » 30 Sep 2013 11:01

bars143 wrote:something in wget.exe does not allowed dowloaded URLs with like of "https://...." but removing "s" using my bat script and this result: "http://...." got working. :)

Code: Select all

FindRepl "\.jpg[\w\+Ñ]+https:" "\.jpg\r\nhttp:" < download-list.txt > download-list-new.txt
:wink:

Antonio

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: help removing and replacing string between specified str

#7 Post by bars143 » 30 Sep 2013 20:36

Aacini wrote:
bars143 wrote:something in wget.exe does not allowed dowloaded URLs with like of "https://...." but removing "s" using my bat script and this result: "http://...." got working. :)

Code: Select all

FindRepl "\.jpg[\w\+Ñ]+https:" "\.jpg\r\nhttp:" < download-list.txt > download-list-new.txt
:wink:

Antonio


thanks AAcini,


aside for string replacement(matching), it also do rename(conversion) --at the same time in one go :!: a great :idea:

and worth a try. :)


Bars

Post Reply