Jump to content

Recommended Posts

Posted

I installed wingnu32 and perl and I try to run such command that should get Title from tags <title>Title</title>

I am not sure, is it possible to run this program in cmd? Maybe I have wrong quoting? I tried few things

1.
for /f "delims=" %a in ('dir /b *.a') do (
pcretest.exe -nle 'print $& if /(?<=title>).*(?=<\/title)/' < %a
)

2.
for /f "delims=" %a in ('dir /b *.a') do (
pcretest.exe -ln0e '$,="\n";print /(?<=<title>).*?(?=<\/title)/sg' < %a
)

3.
for /f "delims=" %a in ('dir /b *.a') do (
%a | pcretest.exe -nle 'print $& if /(?<=title>).*(?=<\/title)/'
)

but I am getting error like: > not expected here...


Posted

For all instances in CMD scripts, use %%a in place of %a. ;)

Posted (edited)

For all instances in CMD scripts, use %%a in place of %a. ;)

Sure but this is not batch script, this is directy in CMD, so this %a is correct.

Edited by DosCode
Posted

I wouldn't use pcretest there but sed from the unixtools:

for /f "delims=" %a in ('dir /b *.a') do (type %a | sed.exe -n "s/<title>\(.*\)<\/title>/\1/Ip")

Thanks. I didn't like sed because it seemed too hard to understand it, but this example with regex looks really simple and understandable.

Posted

Just make sure that you are searching for a title tag

  • <Title>Required Title Text</TITLE>
    or a title with attribute tag
  • <title="My Title">Required Title Text</TITLE>

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...