Batch file regexp

April 14, 2009 at 11:38:23
Specs: Windows XP
Hi,

I'm trying to extract a sting (e.g. 117.BSI.M.U2.N.A.A20.I.1.U2.2240.Z01.E) from a html file I've downloaded with curl in a batch script.

In my example I'm trying to find:
[0-9][0-9][0-9].%ecbKey%

in e.g.
http://sdw.ecb.europa.eu/search.do?...

(here %ecbKey% = BSI.M.U2.N.A.A20.I.1.U2.2240.Z01.E)

The best I can come up with is:
curl -s -d "type=serieskey&q=%ecbKey%" http://sdw.ecb.europa.eu/search.do -o temp.txt
for /f "usebackq tokens=4 delims==" %%g in (`findstr /r "[0-9][0-9][0-9].%ecbKey%" temp.txt`) do echo %%g

However, this returns ""117.BSI.M.U2.N.A.A20.I.1.U2.2240.Z01.E" />" instead of '117.BSI.M.U2.N.A.A20.I.1.U2.2240.Z01.E'

Any suggestions would be highly appreciated.


See More: Batch file regexp

Report •


#1
April 14, 2009 at 18:29:43
i see you can use curl, therefore i assume you can download tools. (see my sig)
C:\test>set a=BSI.M.U2.N.A.A20.I.1.U2.2240.Z01.E
C:\test>grep -o [0-9][0-9][0-9].%a% temp.txt
117.BSI.M.U2.N.A.A20.I.1.U2.2240.Z01.E
117_BSI_M_U2_N_A_A20_I_1_U2_2240_Z01_E
117.BSI.M.U2.N.A.A20.I.1.U2.2240.Z01.E

C:\test>grep -o [0-9][0-9][0-9].%a% file.txt|head -1
117.BSI.M.U2.N.A.A20.I.1.U2.2240.Z01.E

Unix Win32 tools | Gawk for Windows


Report •

#2
April 15, 2009 at 01:27:19
Thanks, that's very helpful

Report •

Related Solutions


Ask Question