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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:29:00+00:00 2026-05-31T16:29:00+00:00

I don’t know if it’s actually possible to do, but I have a text

  • 0

I don’t know if it’s actually possible to do, but I have a text file that contains some lines which use only the ascii Carriage Return (CR) character, and doesn’t follow it with a Line Feed (LF) character.

My problem is that I’m trying to use the FIND command to search for a string in file, but I can’t get it to return any of the lines with CR (It does return CR+LF lines, obviously).

Is there any way that I can search these lines using native batch commands?

  • 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-31T16:29:02+00:00Added an answer on May 31, 2026 at 4:29 pm

    I have exhaustively tested FINDSTR, and I know that it will treat the entire file as one line if it only has <CR> and no <LF>.

    I haven’t done the same level of testing with FIND, but I suspect it will have the same problem. But I can’t say for sure at the moment.


    Edit 1

    I have confirmed (on Vista anyway), that FIND breaks lines strictly after <LF>, with or without the <CR> before it. The <CR> character is simply treated as another character.

    You shouldn’t have any problem searching for lines that have embedded <CR> in them. The problem will be how the output looks on the screen. Also, multiple logical lines will be treated as a single line (those “ending” with <CR>).

    I created a test.txt file with the following structure

    1<CR><LF>
    2<CR><LF>
    3<CR>4<CR>5<CR><LF>
    6<CR><LF>
    7<CR><LF>
    

    And then used FIND against it

    FIND "2" <test.txt
    -> 2
    
    FIND "3" <test.txt
    -> 5
    
    FIND "4" <test.txt
    -> 5
    
    FIND "5" <test.txt
    -> 5
    
    FIND "6" <test.txt
    -> 6
    

    The output looks weird when searching for 3 and 4, but it is actually correct. That is because 3, 4 and 5 are all on the same line. FIND prints out the entire line, but the carriage returns cause the 3 to be overwritten by the 4, and the 4 is overwritten by the 5. It becomes more obvious if I do FIND "3" <test.txt >out.txt – it produces a file of length 7 bytes.

    You will get basically the same results if you use FINDSTR.

    You cannot force FIND (or FINDSTR) to break lines at a lone <CR>. But you can preprocess your file to convert the lone <CR> chars into Windows standard line terminators using the following simple hybrid script. The script takes the name of the file to convert as the 1st and only parameter.

    The meat of the conversion is done with JScript, and the rest with batch. It’s probably silly to use a hybrid – the whole thing could have been done with JScript (or VBScript), but the hybrid was fun. And you can easily add additional batch commands as you see fit. For example, you could add your FIND command after the MOVE but before the EXIT /B.

    Warning – the script over-writes the original text file. Remove the MOVE command if you want the modified version to be a separate file.

    @if (@x)==(@y) @end /* harmless valid code for both batch and Jscript
    ::********* Batch Part **************************************************
    :: This batch script calls the JScript below to normalize the end-of-line
    :: for the contents of the file name passed in as parameter 1.
    :: It redirects JScript to read its input from the file, and writes the
    :: output to a new file. The batch script than moves the new file to 
    :: replace the original.
    ::
    :: You could put your FIND command after the MOVE and before the EXIT /B.
    ::
    @echo off
    <%1 cscript //e:jscript /nologo "%~f0" >"%~1.new"
    move "%~1.new" "%~1" >nul
    exit /b
    
    *********** JScript Part **************************************
    * This little script reads stdin, normalizes the end-of-line,
    * and writes the result to stdout
    *
    * <CR><LF> -> no change
    * <LF> without preceding <CR> -> <CR><LF>
    * <CR> without following <LF> -> <CR><LF>
    */
    while (!WScript.StdIn.AtEndOfStream) {
      WScript.StdOut.WriteLine(WScript.StdIn.ReadLine().replace( /\r/g, "\r\n" ) );
    }
    

    Edit 2

    I just realized there is a totally non-destructive method to search the “lines” terminated by <CR> if I just slightly modify my script above. Besides making the necessary changes, I eliminated the comments.

    The script now takes 2 arguments: “searchString”, “fileName”

    @if (@x)==(@y) @end /* harmless valid code for both batch and Jscript
    ::********* Batch Part **********************************************
    @echo off
    <%2 cscript //e:jscript /nologo "%~f0" | find "%~1"
    exit /b
    
    *********** JScript Part *******************************************/
    while (!WScript.StdIn.AtEndOfStream) {
      WScript.StdOut.WriteLine(WScript.StdIn.ReadLine().replace( /\r/g, "\r\n" ) );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DON'T ASK WHY but... I have a regex that needs to be case insensitive
Don't know why but I can't find a solution to this. I have 3
Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to google for such, but is there a way to query
I have just tried to save a simple *.rtf file with some websites and
Don't know if I worded the question right, but basically what I want to
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know how to explain it better but i'm trying to get a response
Don't know if anyone can help me with this or if it's even possible.
Don't know whats exactly going on, but it's definitely killing my time for nothing.

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.