Help with findstr

Stu 1 Reputation point
2020-08-03T08:11:08.117+00:00

Hi

I'm looking for some guidance in regard to using findstr (i'm not too tech savvy, and i don't have admin rights to the PC - if that is going to restrict what i am trying to do).

I have to identify a specific text string in a data file (a *.flt file) within a specific byte location, and then return a string from another specific byte location.

i.e
Within my data exists "01" within byte reference <101-102>, when the line starts with "001" (this could also contain other variables, but i am just interested in where the value is "01"

My data extract contains different lines of data, all starting with repeating numbers -
i.e line 1 = "001", line 2 = "300", then line 3 might rettur to "001" again.

When i get a "hit", i would want a specific byte reference to be returned.
i.e <108-114>

Is this possible by using FINDSTR?

i've got as far as listing the values i want to find in a text file, and then listing the files i want to search in another text file (like the example on the MS website)

Findstr /g:stringlist.txt /f:filename.txt >results.out

I guess the question i am trying to ask is - is it possible to define what is returned in the results.

I've added "/n" before results which is pretty good, it returns the line number, but this isn't specific enough for me - especially when i have over 1,000 variables to locate.

Thanks in advance for any tips/help. Appreciate i might be asking way too much from Findstr, and it might be better suited to an SQL query (which i wouldn't have a clue about).

Many thanks

Stu

o

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,651 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 34,421 Reputation points
    2020-08-05T17:50:04.877+00:00

    I would think that Powershell would be a better solution. Use Get-ChildItem to get file objects and then use Get-Content to read the file content. A For-Each loop can then process each line to look to see if the record should be processed. Then use the .SubString method to pick off the data at certain positions.

    powershell

    Windows-PowerShell-4


  2. Rita Han - MSFT 2,166 Reputation points
    2020-08-06T06:56:52.767+00:00

    Hello,

    where the value is "01"

    "/o" parameter can prints character offset before each matching line.

    Take this as an example:

    16061-20200806-1.png

    Result:

    15970-20200806-2.png

    As other specific requirements you may check PowerShell solution or write an application to get exactly what you want.

    Thank you!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.