Page 1 of 1

Findstr without pipe

Posted: 18 Jun 2018 01:12
by Bucko
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.

Re: Findstr without pipe

Posted: 18 Jun 2018 08:45
by Aacini
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

Re: Findstr without pipe

Posted: 18 Jun 2018 09:45
by Bucko
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

Re: Findstr without pipe

Posted: 21 Jun 2018 09:07
by penpen
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