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

  • SEARCH
  • Home
  • 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 8773405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:17:13+00:00 2026-06-13T18:17:13+00:00

I am having some trouble writing a script that will find a string iff

  • 0

I am having some trouble writing a script that will find a string iff the string occurs on higher line number than a previously found string.

FIND /N "BEGIN" "TEST_LOG.txt" && FIND "[ERROR" TEST_LOG.txt && EXIT /B 255

This string will first return an exit code of 255 if the log has been written (“BEGIN” will always appear) and the second string “[ERROR” is found.

Because it is desirable to append to the log file I would like to ONLY look for “[ERROR” on line numbers > the max line number discovered in the FIND /N “BEGIN” statement.

For example, with a log file like this:

BEGINNING 12:03:45.17
BEGINNING 12:03:45.17
BEGINNING 12:03:45.17
BEGINNING 12:03:45.17
[ERROR

I would expect the code to exit with error code 255.
But, with a log file like this I would not:

BEGINNING 12:03:45.17
BEGINNING 12:03:45.17
[ERROR
BEGINNING 12:03:45.17
BEGINNING 12:03:45.17
ALL IS WELL!

I look forward to your replies and thank you in advance of your help.

  • 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-06-13T18:17:14+00:00Added an answer on June 13, 2026 at 6:17 pm

    You simply need to establish the highest line number that each strings appears, and exit if the [ERROR string line number is greater than for BEGIN. Use a FOR /F loop to process each matching line from FINDSTR /N and set a variable to the line number. The last match processed wins, and will be the highest occurrence. You need two loops – one for each search string.

    I used the FINDSTR /B option to only match if the string appears at the beginning of the line. Obviously you can remove that option if it is not your requirement.

    @echo off
    setlocal
    set begin=0
    set error=0
    for /f "delims=:" %%N in ('findstr /nlb BEGIN TEST_LOG.txt') do set /a begin=%%N
    for /f "delims=:" %%N in ('findstr /nlb [ERROR TEST_LOG.txt') do set /a error=%%N
    if %error% gtr %begin% exit /b 255
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some trouble writing a regex expression that will strip outer brackets
I am having some trouble with writing a unit test that checks my custom
I'm having some trouble with a jquery script I'm writing, as I cannot get
I am having trouble writing some Java code, which will create a container/folder in
I'm having some trouble writing a GUI in Java that can interact with Tcl
I'm having some trouble writing the SQL statement for the following request: Find the
Im having some trouble writing a getstring function, this is what I have so
I am having some trouble with writing classes in Arduino. Here is a class
I'm new to linq and having trouble writing two simple queries. For some reason,
I'm having some trouble writing a regex for a telephone numbers. (not too great

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.