Double quotes in For loop input [SOLVED]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Double quotes in For loop input [SOLVED]

#16 Post by Ed Dyreen » 28 Jun 2012 13:47

doscode wrote:But when I replace it, I have %~$ in !$!

Code: Select all

@echo off &setlocal enableDelayedExpansion
for %%? in ( "C:" ) do for %%$ in ("filename.txt") do echo.%%$=%%~$PATH:?_
pause
exit

Code: Select all

"filename.txt"=C:\_
Druk op een toets om door te gaan. . .
but why ?

Code: Select all

for /?
...
% ~ $ PATH: I - searches the directories in the PATH environment variable and expands
                  % I to the fully qualified name of the first
                  file found. If the name of the environment variable
                  is not specified or if the file is not found,
                  then this modifier expands to the empty
                  string.
...
pause
foxidrive wrote:No. Use a, b or c


Using ? is ill advised. There is no advantage to using ? only drawbacks.
aGerman wrote:Alpha characters have also side effects. For that reason it's really nothing but a question of the style one would prefer.

Code: Select all

@echo off &setlocal

del "dummy.txt" 2>nul
for %%a in ("dummy.txt") do echo %%~aa
for %%A in ("dummy.txt") do echo %%~Aa
for %%A in ("dummy.txt") do echo %%~AA

>>"dummy.txt" type nul
for %%a in ("dummy.txt") do echo %%~aa
for %%A in ("dummy.txt") do echo %%~Aa
for %%A in ("dummy.txt") do echo %%~AA

pause

Result:

Code: Select all

ECHO ist ausgeschaltet (OFF).
dummy.txta
ECHO ist ausgeschaltet (OFF).
--a------
dummy.txta
--a------
Drücken Sie eine beliebige Taste . . .

All the characters with special meaning for arguments or FOR variables have those effects.

Regards
aGerman
http://www.dostips.com/forum/viewtopic.php?p=14254#p14254
doscode wrote:I have all letters reserved for tokens A-Z.

Maybe I could use more letters [a-zA-Z] but I don't know if is it possible?

Code: Select all

@echo off &setlocal enableDelayedExpansion

for %%a in (

   "It's always better to ask someone to test it for you,"

) do   for %%A in (

   "than testing it yourself."

) do    echo.%%~a^

%%~A

pause
exit

Code: Select all

It's always better to ask someone to test it for you,
than testing it yourself.
Druk op een toets om door te gaan. . .

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Double quotes in For loop input [SOLVED]

#17 Post by foxidrive » 29 Jun 2012 01:49

Yes you can use more ascii characters - they follow the ascii table. a-z does not immediately precede A-Z

For example if you use ? then you can use
%%?
%%@
%%A
%%B
%%C to %%Z and beyond.

Beware the poison characters.


I can't help but wonder if your technique could be improved. Using 26 variables is not something that is usual and there may be easier techniques.
If you want some help then you'd need to provide the URL to get the source data and explain which parts of the data that you need.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: Double quotes in For loop input [SOLVED]

#18 Post by doscode » 29 Jun 2012 01:54

Whole problem is in parsing the html file. The line with IP addess contains many of tags, like spans and divs. So when I use this code to parse it:

Code: Select all

REM For all files of proxy list 3
FOR %%? IN (%proxy_list_3%) DO (
echo %%?
FOR /F "tokens=1-27 delims=<>" %%A IN ('grep -B 1411 -E "</table>" %%? ^| grep -E ^"^(display^|^>[0-9]{1^,2}^<^|[0-9][0-9][0-9]^|[0-9][0-9]{1^,2}^</td^>^|flag^|^<td^>HTTP^|rightborder^).*$^" ') DO (
  if !cnt! EQU 0 SET /A breaked=0
 
  set a=%%A&set b=%%B&set c=%%C&set d=%%D&set e=%%E&set f=%%F
  set g=%%G&set h=%%H&set i=%%I&set j=%%J&set k=%%K&set l=%%L
  set m=%%M&set n=%%N&set o=%%O&set p=%%P&set q=%%Q&set r=%%R&set s=%%S
  set t=%%T&set u=%%U&set v=%%V&set w=%%W&set x=%%X&set y=%%Y&set z=%%Z
  if NOT "%%A" == "" set a=!a:"=!
  if NOT "%%B" == "" set b=!b:"=!
  if NOT "%%C" == "" set c=!c:"=!
  if NOT "%%D" == "" set d=!d:"=!
  if NOT "%%E" == "" set e=!e:"=!
  if NOT "%%F" == "" set f=!f:"=!
  if NOT "%%G" == "" set g=!g:"=!
  if NOT "%%H" == "" set h=!h:"=!
  if NOT "%%I" == "" set i=!i:"=!
  if NOT "%%J" == "" set j=!j:"=!
  if NOT "%%K" == "" set k=!k:"=!
  if NOT "%%L" == "" set l=!l:"=!
  if NOT "%%M" == "" set m=!m:"=!
  if NOT "%%N" == "" set n=!n:"=!
  if NOT "%%O" == "" set o=!o:"=!
  if NOT "%%P" == "" set p=!p:"=!
  if NOT "%%Q" == "" set q=!q:"=!
  if NOT "%%R" == "" set r=!r:"=!
  if NOT "%%S" == "" set s=!s:"=!
  if NOT "%%T" == "" set t=!t:"=!
  if NOT "%%U" == "" set u=!u:"=!
  if NOT "%%V" == "" set v=!v:"=!
  if NOT "%%W" == "" set w=!w:"=!
  if NOT "%%X" == "" set x=!x:"=!
  if NOT "%%Y" == "" set y=!y:"=!
  if NOT "%%Z" == "" set z=!z:"=!
  call :innerLoop

I can run out of variables. I thought it could help to remove spaces from begin of the lines and <span></span> which are not necessary and takes at least 3 tokens.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Double quotes in For loop input [SOLVED]

#19 Post by Ed Dyreen » 29 Jun 2012 02:04

'
I wondered before why u wanted unique access to 26 different tokens.
In a previous topic, I posted a solution that accomplished what you wanted without the need for 26 tokens.

PS: You write illogical codes, people post good solutions, you discard them, write some more illogical codes and then ask questions about it. I am annoyed now.

jeb
Expert
Posts: 1041
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Double quotes in For loop input [SOLVED]

#20 Post by jeb » 29 Jun 2012 02:16

Ed Dyreen wrote:I wondered before why u wanted unique access to 26 different tokens.
In a previous topic, I posted a solution that accomplished what you wanted without the need for 26 tokens.

PS: You write illogical codes, people post good solutions, you discard them, write some more illogical codes and then ask questions about it. I am annoyed now.


So we can conclude he must be a business student :wink:

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: Double quotes in For loop input [SOLVED]

#21 Post by doscode » 29 Jun 2012 02:35

foxidrive wrote:Yes you can use more ascii characters - they follow the ascii table....

Beware the poison characters.

So can I use [,\,] as the characters after Z? Or backslash is poison character?
Last edited by doscode on 29 Jun 2012 02:41, edited 1 time in total.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: Double quotes in For loop input [SOLVED]

#22 Post by doscode » 29 Jun 2012 02:36

Ed Dyreen wrote:'
In a previous topic, I posted a solution that accomplished what you wanted without the need for 26 tokens.

I am not sure about which post do you speak. Maybe I have overlooked something.

Also I did not know there will be so many tokens. On the begin, I though about A-J characters could be enough.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Double quotes in For loop input [SOLVED]

#23 Post by foxidrive » 29 Jun 2012 02:43

I believe those characters will work, but you can test it.


What was the URL for the proxy website again, and what information do you need from the HTML.
Maybe someone here will be interested enough to investigate it and you can get some alternate options.



Doscode, I must agree that you do refuse to listen to people that might know techniques that can help you. Somehow you want to achieve the solution by yourself... and I can understand the enjoyment in doing it yourself, but maybe in this project you can use the collective experience of a couple of hundred years from all the contributors here...

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: Double quotes in For loop input [SOLVED]

#24 Post by doscode » 29 Jun 2012 03:17

The site is
hidemyass.com/proxy-list/

foxidrive wrote:Doscode, I must agree that you do refuse to listen to people that might know techniques that can help you. Somehow you want to achieve the solution by yourself... and I can understand the enjoyment in doing it yourself, but maybe in this project you can use the collective experience of a couple of hundred years from all the contributors here...

I do not refuse to listen. I was learn that when I want something I cannot expect that others will do it instead me. I doubt somebody would take care about doing my things. It's hard to me to explain what exactly I want and how it should work, because the script is long and treacherous. And last thing is that I would not remember things if I would not write it on my way. But a lot I have learn here, but it is long way because the CMD is much more treacherous than other languages I used learn in few weeks. But to me it is really big contribution when I can create own programs which work with file system.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Double quotes in For loop input [SOLVED]

#25 Post by foxidrive » 29 Jun 2012 06:35

CMD is treacherous because of it's flaws in handling poison characters and not having a full feature set so we resort to kludges.

Some of us are here to help people gain some experience with batch and to solve some tasks for people. You can take advantage of much experience from the people here and who may be able to see improved ways of handling a task, because we have often done similar things in the past.

But now from http://hidemyass.com/proxy-list/ it has these headers. Which information do you need extracted and into what format?

Last update
IP address
Port
Country
Speed
Connection time
Type
Anonymity

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Double quotes in For loop input [SOLVED]

#26 Post by foxidrive » 29 Jun 2012 06:53

I can get this format pretty easily and then it can be parsed further. What format and information do you need?

Those large numbered IP addresses I see now are attempts to stop people stripping out the information.

Code: Select all

  21 secs   4663.252214107.244.178          3128   Russian                            HTTPS   High +KA   
  21 secs   201.22.5974.55                  3128   Brazil                             HTTP    Low       
  21 secs   117209.103201.6875.114          3128   Indonesia                          HTTP    Low       
  21 secs   200.1102651.1809018.33          8080   Argentina                          HTTP    Low       
  21 secs   201205.116.187.236              3128   Mexico                             HTTPS   High +KA   



This is what my script generates:

Code: Select all

  21 secs   46.252.244.178    3128   Russian                            HTTPS   High +KA   
  21 secs   201.22.59.55      3128   Brazil                             HTTP    Low       
  21 secs   117.103.68.114    3128   Indonesia                          HTTP    Low       
  21 secs   200.110.180.33    8080   Argentina                          HTTP    Low       
  21 secs   201.116.187.236   3128   Mexico                             HTTPS   High +KA   
  21 secs   177.43.203.122    8080   Brazil                             HTTPS   High +KA   
  21 secs   182.52.114.41     3128   Thailand                           HTTPS   High +KA   
  1         200.42.69.94      8080   Argentina                          HTTPS   High +KA   
  1         178.48.2.237      8080   Hungary                            HTTPS   High +KA   
  1         201.6.108.59      3128   Brazil                             HTTP    Low       
  1         218.248.4.101     8080   India                              HTTPS   High +KA   
  2         219.83.100.202    8080   Indonesia                          HTTPS   High +KA   
  2         94.42.176.108     80     Poland                             HTTPS   High +KA   
  2         118.97.71.57      3128   Indonesia                          HTTPS   High +KA   
  2         186.227.174.242   3128   Brazil                             HTTPS   High +KA   
  2         115.236.19.234    80     China                              HTTP    Low       
  2         187.16.138.51     3128   Brazil                             HTTP    Low       
  3         201.251.62.137    8080   Argentina                          HTTPS   High +KA   
  3         95.215.48.158     8080   Ukraine                            HTTPS   High +KA   
  4         202.182.172.2     3128   Indonesia                          HTTPS   High +KA   
  4         93.153.171.82     8080   Russian                            HTTPS   High +KA   
  4         190.121.143.254   8080   Colombia                           HTTPS   High +KA   
  4         78.159.216.28     8080   Italy                              HTTP    Low       
  4         201.49.77.3       8080   Brazil                             HTTPS   High +KA   
  5         189.2.162.165     3128   Brazil                             HTTPS   High +KA   
  5         190.254.196.211   3128   Colombia                           HTTPS   High +KA   
  5         200.150.66.226    3128   Brazil                             HTTP    Low       
  5         212.156.91.198    80     Turkey                             HTTP    Low       
  5         220.181.72.199    80     China                              HTTP    Low       
  6         72.64.146.136     3128   United                             HTTPS   High +KA   
  6         101.255.36.234    81     China                              HTTPS   High +KA   
  6         72.64.146.136     8080   United                             HTTPS   High +KA   
  6         69.162.119.220    3128   United                             HTTPS   High +KA   
  6         88.146.243.118    8080   Czech                              HTTPS   High +KA   
  6         79.101.37.131     8080   Serbia                             HTTPS   High +KA   
  6         187.60.96.7       3128   Brazil                             HTTPS   High +KA   
  7         200.171.182.128   3128   Brazil                             HTTPS   High +KA   
  7         95.31.18.119      3128   Russian                            HTTPS   High +KA   
  7         190.206.44.35     8080   Venezuela                          HTTPS   High +KA   
  7         210.246.88.46     8080   Thailand                           HTTPS   High +KA   
  7         217.119.81.106    3128   Russian                            HTTPS   High +KA   
  7         210.4.97.107      3128   Philippines                        HTTPS   High +KA   
  7         209.172.34.132    3128   Canada                             HTTP    Low       
  7         95.215.48.130     8080   Ukraine                            HTTP    Low       
  7         218.65.230.212    8080   China                              HTTPS   High +KA   
  7         118.96.153.181    8080   Indonesia                          HTTP    Low       
  8         219.83.100.195    8080   Indonesia                          HTTPS   High +KA   
  8         203.66.41.51      8080   Taiwan,                            HTTP    High +KA   
  8         201.22.249.114    3128   Brazil                             HTTPS   High +KA   
  8         82.117.144.41     8080   Czech                              HTTPS   High +KA   

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: Double quotes in For loop input [SOLVED]

#27 Post by doscode » 29 Jun 2012 13:29

IP, port, country, type (http/https/ftp), anonymity
My final target is to gain the information for http proxy with the High +KA information.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Double quotes in For loop input [SOLVED]

#28 Post by foxidrive » 29 Jun 2012 20:03

This takes filein.htm from the website, and could use wget for that, and creates
file.htm
file.out
file.txt

It uses GnuSED for Windows and HTMSTRIP from Bruce Guthrie
I don't see any advantage to doing it purely in batch because the web site is bound to change the HTML format and maintaining a pure batch version would be unpleasant.

Code: Select all

@echo off
setlocal enabledelayedexpansion
sed -e "s/<div style=\x22display:none\x22>[0-9]*<\/div>//g" -e "s/<span style=\x22display:none\x22>[0-9]*<\/span>//g" filein.htm >file.htm
htmstrip file.htm
find "TP" <file.out |find /v ">" >file.txt

for /f "delims=" %%a in (file.txt) do (
set var=%%a
set var=!var:~12!
for /f "tokens=1,2,3,4,*" %%b in ("!var!") do (
if /i "%%f"=="High +KA   " echo %%b,%%c,%%d,%%e,%%f
)
)
pause



Of course remove 'if /i "%%f"=="High +KA "' to get the full list.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: Double quotes in For loop input [SOLVED]

#29 Post by doscode » 30 Jun 2012 01:55

Thanks.

This is on my screen:

Code: Select all

HTMSTRIP (/? for help)   (c)2002 Bruce Guthrie, Wayne Software   Rev 08/10/2002
Options: /WIDTH=80 /-FORCE /RULE=- /-RSPACE /A=NONE /IMG=NONE /MAP=NONE
         /EXT=.OUT /INDENT /INPUT /-SPACES /TABLE /-WARNINGS /-ALL
         /BORDER=T /BUFF=1 /Cp:\server\loop\ /ATTR=-H-S
09:51:51: Using system-defined default entity lookup table
09:51:51: Processing HTML files...  Press Esc to abort early
09:51:51: FILE.HTM     --> FILE.OUT
  Input file size:     61,044 bytes (100%)
09:51:51: Done
Press any key to continue...

This is one line from the file, there are not IPs.

Code: Select all

| 6 hours and 21  | 3128    | Venezuela  |         |       | HTTPS      | High   |           |

I tried argument for removing extra spaces and to remove table.

Code: Select all

htmstrip file.htm /BUFF=0 /-TABLE

The first removed spaces from left, and the second generated:

Code: Select all

6 hours and 21 minutes 190.37.135.49  | 3128  | Venezuela  |  |  | HTTPS  |

Yet I don't need the time the (first column).

Can you remove spaces (left/right) from the output file?

The reason why I tried to do it purely in batch is, that I wanted to publish my program and did not want user of the program would need to install other programs. The gnuwin32 exists for more systems (I cannot find the site where I downloaded from but I think that 64 bit systems have different version). So this is the problem of compatibility. I wanted to do it simple to install, so the used would just run the program without downloading sed.

I would like to use the script* for testing proxy speed to change the table, that you extracted. There are two free columns, so I could insert there the delay and level of speed. I should probably do it with sed, but how to insert the two values there. Expecting no spaces are between word and |. I expect that I will occasionally check and update the delays and speeds.

* - the David's Benham script:
http://stackoverflow.com/questions/1100 ... ext-in-cmd

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Double quotes in For loop input [SOLVED]

#30 Post by foxidrive » 30 Jun 2012 04:11

My HTMSTRIP.INI file has been changed - try this:

Code: Select all

@echo off
setlocal enabledelayedexpansion
sed -e "s/<div style=\x22display:none\x22>[0-9]*<\/div>//g" -e "s/<span style=\x22display:none\x22>[0-9]*<\/span>//g" filein.htm >file.htm
htmstrip /-table /border=b file.htm
find "TP" <file.out |find /v ">" >file.txt

for /f "delims=" %%a in (file.txt) do (
set var=%%a
set var=!var:~12!
for /f "tokens=1-6" %%b in ("!var!") do (
if /i "%%f%%g"=="High+KA" echo %%b,%%c,%%d,%%e,%%f,%%g
)
)
pause


Sed can probably be changed to WSH and that will make plain batch easier I think.
Last edited by foxidrive on 30 Jun 2012 04:28, edited 1 time in total.

Post Reply