Computing.Net > Forums > Programming > Batch parse help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch parse help

Reply to Message Icon

Name: skakkola
Date: October 16, 2007 at 03:20:30 Pacific
OS: win xp
CPU/Ram: 512
Product: intel
Comment:

Hello,
I have a txt file:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<TITLE>FTP Listing of /xx/xxx/xxx/xx/ at xxx.xxx.xxx</TITLE>
<BASE HREF="ftp://xxx/wxx/xxx/xxx/xx/">
</HEAD>
<BODY>
<H2>FTP Listing of /xx/xxxx/xxx/xx/ at xxxx.xxx.xxx</H2>
<HR>
Parent Directory

<PRE>
Oct 10 2007 19:54 Directory images
Apr 25 2007 00:00 109153 x200715.zip
May 02 2007 00:00 106609 x200716.zip
May 09 2007 00:00 101234 x200717.zip
May 16 2007 00:00 58686 x200718.zip
May 23 2007 00:00 35036 x200719.zip
May 30 2007 00:00 40317 x200720.zip
Jun 06 2007 00:00 47291 x200721.zip
Jun 13 2007 00:00 80062 x200722.zip
Jun 20 2007 00:00 49223 x200723.zip
Jun 27 2007 00:00 51423 x200724.zip
Jul 04 2007 00:00 69741 x200725.zip
Jul 11 2007 00:00 57379 x200726.zip
Jul 18 2007 00:00 67033 x200727.zip
Jul 25 2007 00:00 44308 x200728.zip
Aug 01 2007 00:00 46946 x200729.zip
Aug 08 2007 20:09 58157 x200730.zip
Aug 16 2007 06:05 74215 x200731.zip
Aug 22 2007 20:07 74415 x200732.zip
Aug 29 2007 20:08 49555 x200733.zip
Sep 05 2007 20:07 30297 x200734.zip
Sep 12 2007 20:05 46637 x200735.zip
Sep 20 2007 08:06 43482 x200736.zip
Sep 26 2007 20:13 46957 x200737.zip
Oct 03 2007 20:11 46751 x200738.zip
Oct 10 2007 20:06 68676 x200739.zip
</PRE>

I need the number of the first file:
here the first file is x200715.zip
I need the 15!!!
please help



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: October 16, 2007 at 03:46:43 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

find "zip" < my.txt > ziplist

for /f "tokens=* delims= " %%a in (ziplist) do (
if not !N!'==' goto :eof
echo %%a | find "zip" > nul
if not errorlevel 1 (
set str=%%a
set str=!str:~-6!
set N=!str:~0,2!
)
echo number of the first zip is !N!
)



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 2
Name: skakkola
Date: October 16, 2007 at 04:04:11 Pacific
Reply:

Thankx, but I get incorrct syntax error...


0

Response Number 3
Name: Mechanix2Go
Date: October 16, 2007 at 04:30:26 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('find "zip" ^< my.txt') do (
if not !N!'==' goto :eof
set str=%%a
set str=!str:~-6!
set N=!str:~0,2!
echo number of the first zip is !N!
)



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 4
Name: skakkola
Date: October 16, 2007 at 06:41:53 Pacific
Reply:

That's good, thakx,
but I need to use it IN another script, so that the set 'setLocal EnableDelayedExpansion' is not good...
Is there a way to do it without this option?


0

Response Number 5
Name: IVO
Date: October 16, 2007 at 07:58:45 Pacific
Reply:

Salve simone,

@echo off
Set N=
for /f "tokens=*" %%a in ('find "zip" ^< my.txt') do (
Call :PARSE %%a)
GoTo :EOF

:PARSE
If not %N%'==' GoTo :EOF
set str=%*
set str=%str:~-6%
set N=%str:~0,2%
echo number of the first zip is %N%
GoTo :EOF

Here the drawback is the need to perform the whole file parsing even if the target is achieved.


0

Related Posts

See More



Response Number 6
Name: skakkola
Date: October 16, 2007 at 08:22:33 Pacific
Reply:

Grazie Ivo, and thanks Mechanix2Go!!!

it works!! (both)


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch parse help

Batch Scripting Help www.computing.net/answers/programming/batch-scripting-help/14192.html

Batch parse user input www.computing.net/answers/programming/batch-parse-user-input/16804.html

batch file help www.computing.net/answers/programming/batch-file-help/13830.html