Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7543711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:29:55+00:00 2026-05-30T08:29:55+00:00

Task in CMD. 1) How can I compare if string is in string? I

  • 0

Task in CMD.

1) How can I compare if string is in string? I checked manual here for “Boolean Test “does string exist ?”” But I can’t understand the example or it does not work for me. This piece of code, it is just a try. I try to make a string compare of filter some sting if there is a tag <a> in a line.

FOR /f "tokens=* delims= usebackq" %%c in ("%source%") DO ( 
echo %%c
IF %%c == "<a" (pause) 
)

So while I read a file, it should be paused if there is a link on a line.

2) I have one more ask. I would need to filter the line if there is a specific file in the link, and get content of the link. My original idea was to try to use findstr with regex, but it seems not to use sub-patterns. And next problem would be how to get the result to variable.

set "pdf=0_1_en.pdf"
type "%source%" | grep "%pdf%" | findstr /r /c:"%pdf%.*>(.*).*</a>"

So in summary, I want to go through file and if there is a link like this: REPAIRED: *

<a href="/Dokumenter/dsweb/Get/Document-408/EK_GEN_0_1_en.pdf" class="uline"><b>GEN 0.1 Preface</b></a>
  • I forgot to style this as a code, so the inside of code was not displayed. Sorry.
  • Warnning: we don’t know the path, only the basic filename.

Get the title GEN 0.1 Preface. But you should know, that there are also similar links with same link, which contain image, not a text inside a tag.

Code according Aacini to be changed a little bit:

@echo off
setlocal EnableDelayedExpansion
set "source=GEN 0 GENERAL.html"
set "pdf=0_1_en.pdf"
echo In file:%source%
echo Look for anchor:%pdf%

rem Process each line in %source% file:
for /F "usebackq delims=" %%c in ("%source%") do (
   set "line=%%c"
   rem Test if the line contain a "tag" that start with "<a" string:
   set "tag=!line:*<a=!"
   if not "!tag!" == "!line!" (
      rem Take the string in tag that end in ">"
      for /F "delims=^>" %%a in ("!tag!") do set "link=%%a"
      echo Link found: !link!
      if "!link!" == "GEN 0.1 Preface" echo Seeked link found
   )
)
pause

Still not finished

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:29:56+00:00Added an answer on May 30, 2026 at 8:29 am

    Although your question is extensive it does not provide to much details, so I assumed several points because I don’t know too much about .PDF files, tags, etc.

    @echo off
    setlocal EnableDelayedExpansion
    set "source=GEN 0 GENERAL.html"
    set "pdf=0_1_en.pdf"
    echo In file: "%source%"
    echo Look for anchor: "%pdf%"
    
    rem Process each line in %source% file:
    for /F "usebackq delims=" %%c in ("%source%") do (
       set "line=%%c"
       rem Test if the line contain "<a>" tag:
       set "tag=!line:*<a>=!"
       if not "!tag!" == "!line!" (
          rem Test if "<a>" tag contain the anchor pdf file:
          if not "!tag:%pdf%=!" == "!tag!" (
             rem Get the value of "<b>" sub-tag
             set "tag=!tag:<b>=$!"
             set "tag=!tag:</b>=$!"
             for /F "tokens=2 delims=$" %%b in ("!tag!") do set title=%%b
             echo Title found: "!title!"
          )
       )
    )
    pause
    

    Any missing point can be added or fixed, if you give me precise details about them.

    EDIT: I fixed the program above after last indications from the OP. I used $ character to get the Title value; if this character may exist in original Tag, it must be changed by another unused one.

    I tested this program with this “GEN 0 GENERAL.html” example file:

    Line one
    <a>href="/Dokumenter/EK_GEN_0_X_en.pdf" class="uline"><b>GEN 0.X Preface</b></a>
    Line three
    <a>href="/Dokumenter/EK_GEN_0_1_en.pdf" class="uline"><b>GEN 0.1 Preface</b></a>
    Line five
    

    and get this result:

    In file: "GEN 0 GENERAL.html"
    Look for anchor: "0_1_en.pdf"
    Title found: "GEN 0.1 Preface"
    

    EDIT: New faster method added

    There is a simpler and faster method to solve this problem that, however, may fail if a line contains more than one tag:

    @echo off
    setlocal EnableDelayedExpansion
    set "source=GEN 0 GENERAL.html"
    set "pdf=0_1_en.pdf"
    echo In file: "%source%"
    echo Look for anchor: "%pdf%"
    
    for /F "delims=" %%c in ('findstr /C:"<a>" "%source%" ^| findstr /C:"%pdf%"') do (
       set "tag=%%c"
       rem Get the value of "<b>" sub-tag
       set "tag=!tag:<b>=$!"
       set "tag=!tag:</b>=$!"
       for /F "tokens=2 delims=$" %%b in ("!tag!") do set title=%%b
       echo Title found: "!title!"
    )
    pause
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The task is simple, and the answers might be many. But here goes: On
So I want to automate a manual task using shell scripting, but I'm a
Simple task like make AJAX request , pass one parameter and return result, can
The task is pretty simple, but I've not been able to come up with
Here is my code: -(void)startTask{ NSString * cmd = @/bin/sh; pty_ = [[PseudoTTY alloc]
I have an Azure web app that uses a startup task batch file (addtask.cmd)
I'm trying to open video player in windows 7 with PHP but can't seem
Can I use tstamp property BuildDate in a nant task to an xecutable task
Task: implement paging of database records suitable for different RDBMS. Method should work for
Task at hand — I have three versions of some code, developed by different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.