Findstr without pipe

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Bucko
Posts: 14
Joined: 05 Jun 2018 01:01

Findstr without pipe

#1 Post by Bucko » 18 Jun 2018 01:12

I am using a this batch script to extract a part of a binary file following a delimiter string:

Code: Select all

@echo off
setlocal enabledelayedexpansion

REM Line number of the delimiter line:
for /F "delims=:" %%a in ('findstr /N "^xxyyzz" "Input.bin"') do set "lines=%%a"
echo %lines%

REM Extract the part of the Input.bin following the delimiter line:
< "Input.bin" (

   REM Pass thru the first lines:
   for /L %%i in (1,1,%lines%) do set /P "="

   REM Copy the rest to output bin:
   findstr "^"

) > Output.bin
This is working fine, but with some files I get the error messages "Line ... too long". I know that this problem is associated to piping. I also found the tip:

"The line too long error only happens when FINDSTR reads the input via redirection or a pipe. That error goes away if you pass the name (path) of the file directly to FINDSTR."

My understanding of batch-command syntax is too poor to find out how this could be done in my above script. Can someone here help?

Cheers.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Findstr without pipe

#2 Post by Aacini » 18 Jun 2018 08:45

There is no way that you get what you want from findstr command, no matters how many times you ask the same question...

You may solve your problem via a third party .exe program, as explained at this answer. You may even embeed the ReadFile.exe auxiliary program into the same Batch file that contain the rest of binary files, and extract it via findstr before extract the rest of files...

Antonio

Bucko
Posts: 14
Joined: 05 Jun 2018 01:01

Re: Findstr without pipe

#3 Post by Bucko » 18 Jun 2018 09:45

Aacini wrote:
18 Jun 2018 08:45
There is no way that you get what you want from findstr command, no matters how many times you ask the same question...
Thank you, Aacini, I appreciate your help very much. Yes, this is my third question related to findstr, but it is not the same question. This one is the most reduced one, associated to a concept which is working fine with findstr (extracting from a certain point up to the end of the file).

My hope was that this script could be adapted (by avoiding piping) to overcome the last (?) problem I have. May I understand your answer in such manner that the script basically can not be rewritten in this sense?

(Yes, I understand your suggestions refering to third-party tools. In this special case I shouldn't use them. An alternative would be a simple 'own' auxilliary exe, a code which could be compiled by myself, but until now I failed to find something like this... Such a 'launcher tool' would have to extract at least a part of a binary and run a specified file; and unicode file names should be supported, which makes the coding difficult...)

Cheers, Bucko

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Findstr without pipe

#4 Post by penpen » 21 Jun 2018 09:07

Bucko wrote:
18 Jun 2018 09:45
Yes, this is my third question related to findstr, but it is not the same question.
(...)
My hope was that this script could be adapted (by avoiding piping) to overcome the last (?) problem I have.
Although i'm not Antonio, i also think it is the third time you are asking the question:
"How to xtract data from a certain point up to the end of the file using findstr only?"

Bucko wrote:
18 Jun 2018 09:45
This one is the most reduced one, associated to a concept which is working fine with findstr (extracting from a certain point up to the end of the file).
First, your concept for example fails if a line you want to skip has more than 1024 characters in it.
Second, you miss the fact (which i admit is hard to see) that findstr doesn't extract data from a certain point in your example:
It is the stream (created when redirecting the file "Input.bin"), that extracts data from a certain point (not findstr).

See:
- https://technet.microsoft.com/en-us/lib ... s-lang=cpp
- https://docs.microsoft.com/en-us/cpp/st ... -stream-is


penpen

Post Reply