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 8232061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:42:20+00:00 2026-06-07T17:42:20+00:00

I am trying to extract a string that is located between the first and

  • 0

I am trying to extract a string that is located between the first and second comma in a specific line in a series of text files (subtitle files). The text files are formatted this way:

Subtitles01.txt

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour
Style: Default, Estrangelo Edessa, 57, &H00FFFFFF
Style: Title1, Arno Pro, 65, &H00606066

Subtitles02.txt

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour
Style: OP Eng, Arno Pro, 45, &H00100F11
Style: ED Romaji, Nueva Std Cond, 46, &H00FFFFFF

Subtitles03.txt

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour
Style: OP Eng, Estrangelo Edessa, 45, &H00100F11
Style: Default, Arno Pro, 45, &H00100F11
Style: ED Romaji, Nueva Std Cond, 46, &H00FFFFFF

What I want to achieve here is extract the Fontname for each line that start with “Style: ” and then determine which subtitles contain the fonts I want in a non-repeat manner. So essentially the end result would be output to a textfile like the following;

Subtitles01.txt: Estrangelo Edessa
Subtitles01.txt: Arno Pro
Subtitles02.txt: Arno Pro
Subtitles02.txt: Nueva Std Cond
Subtitles03.txt: Estrangelo Edessa
Subtitles03.txt: Arno Pro
Subtitles03.txt: Nueva Std Cond

Only Subtitles03.txt is needed.

Since Subtitles03.txt contains all the fonts in Subtitles01.txt and Subtitles02.txt, only Subtitles03.txt is needed. The goal is to use the least amount of files to find the unique fonts in all the files. I have came up with the following batch script using findstr to extract the lines starting with “Style: ” but I am stuck beyond that.

@echo off
findstr /B /C:"Style:" *.txt > results.txt
if %errorlevel%==0 (
    echo Found! logged files into results.txt
) else (
    echo No matches found
)

Any help would be appreciated. Thank you guys!

  • 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-07T17:42:22+00:00Added an answer on June 7, 2026 at 5:42 pm

    I imagine it would be much easier to use some other language besides batch, or at least use non-native utilities. But here is a pure native batch solution.

    I don’t see how FINDSTR regex will help with this problem. It cannot extract a portion of the matching line like many other non-native batch regex utilities.

    You can use FOR /F to extract the fonts from each file:

    for /f "tokens=2 delims=," %%A in ('findstr /lb "Style:" file.txt') do echo font=%%A
    

    You can use environment variables to come up with a list of unique fonts. Define variables with the font name in the variable name, all prefixed with font_. Only one variable can be defined for a given name. The assigned value does not matter. You can then use set font_ to list all the unique font names. The number of unique names can be counted, or the actual font name can be parsed out (remove the font_ prefix).

    The tricky part is establishing the minimum set of files required to cover the complete set of unique font names. I imagine someone could come up with an efficient solution. I’ve just employed a brute force recursive permutation method: I count the number of unique fonts found in each permutation and compare the number to the total number of unique fonts. I have added a few shortcuts to not proceed down a particular permutation path if I’ve already found a smaller complete set than the current set.

    The code could be simpler if I used SETLOCAL in my recursion, but batch is limited to only 32 levels of SETLOCAL. I wanted a solution that could support more than 32 files, although I’m a bit worried about performance with that many files.

    Edit -I fixed a bug in my :permuteFiles routine that surfaced once I had more than 3 files

    @echo off
    setlocal enableDelayedExpansion
    
    ::Make sure there are no font_ variables defined
    for /f "delims==" %%A in ('set font_ 2^>nul') do set "%%A="
    
    ::Read all the Subtitle files and
    :: - create an "array" of file names
    :: - create a file of font names for each input file
    :: - create an "associative array" of unique font names
    :: - List the available file/font pairs in the final results
    :: - List the unique fonts in the final results
    set fileCount=0
    >results.txt (
      echo Available fonts
      echo ----------------------------
      for %%F in (subtitles*.txt) do (
        set /a totalFiles+=1
        set "file_!totalFiles!=%%F"
        3>"%%F.fonts" (
          for /f "tokens=2 delims=," %%A in ('findstr /lb "Style:" "%%F"') do (
            set "font_%%A=1"
            >&3 echo %%A
            echo %%F:%%A
          )
        )
      )
      echo(
      echo Unique fonts
      echo ----------------------------
      for /f "delims==" %%A in ('set font_') do (
        set "font=%%A"
        echo !font:~5!
      )
    )
    
    ::Count the number of unique fonts
    for /f %%N in ('set font_ ^| find /c /v ""') do set uniqueFonts=%%N
    
    ::Test all the permutations
    set /a minFileCount=%totalFiles%+1
    for /l %%N in (1 1 %totalFiles%) do (
      call :permuteFiles %%N 0 ""
    )
    
    ::List the required files in the final results
    >>results.txt (
      echo(
      echo The following files contain the complete set of unique fonts:
      echo -------------------------------------------------------------
      for %%N in (%minFileList:~1,-1%) do echo !file_%%N!
    )
    type results.txt
    
    ::Cleanup
    del subtitles*.txt.fonts
    exit /b
    
    
    :permuteFiles  fileNumber  fileCount  fileList
    if %1==%totalFiles% (
      if %2 gtr 0 call :testPermutation %2 %3
      set /a fileCount=%2+1
      if !fileCount! lss !minFileCount! call :testPermutation !fileCount! "%~3,%1"
    ) else (
      set /a nextFile=%1+1
      if %2 gtr 0 call :permuteFiles !nextFile! %2 %3
      set /a "nextFile=%1+1, fileCount=%2+1"
      if !fileCount! lss !minFileCount! call :permuteFiles !nextFile! !fileCount! "%~3,%1"
    )
    exit /b
    
    
    :testPermutation  fileCount  fileList
    for /f "delims==" %%A in ('set font_ 2^>nul') do set "%%A="
    for %%N in (%~2) do (
      for /f "usebackq delims=" %%A in ("!file_%%N!.fonts") do set "font_%%A=1"
    )
    for /f %%N in ('set font_ ^| find /c /v ""') do if %%N==%uniqueFonts% (
      set minFileList=%2
      set minFileCount=%1
    )
    exit /b
    

    Here are the results using your example input:

    Available fonts
    ----------------------------
    Subtitles01.txt: Estrangelo Edessa
    Subtitles01.txt: Arno Pro
    Subtitles02.txt: Arno Pro
    Subtitles02.txt: Nueva Std Cond
    subtitles03.txt: Estrangelo Edessa
    subtitles03.txt: Arno Pro
    subtitles03.txt: Nueva Std Cond
    
    Unique fonts
    ----------------------------
     Arno Pro
     Estrangelo Edessa
     Nueva Std Cond
    
    The following files contain the complete set of unique fonts:
    -------------------------------------------------------------
    subtitles03.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to extract all substrings in a string that is between the
In Ruby, I'm trying to extract from text a string that starts with who
I have a string that I want to extract text between comment tags, manipulate
I'm trying to extract all the text until the first figure that appears. Let's
I'm trying to match chunks of JS code and extract string literals that contain
I have a string that i am trying to extract patterns from, the string
I'm trying to extract the first user-right from semicolon separated string which matches a
I'm trying to extract a string from a text file using 2 delimiters. One
I'm trying to extract the number from a text string and join it to
I'm trying to extract a set of data from some (large) text files. Basically,

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.