Question

I'm piping output from a command to findstr to extract certain lines. Here's my code:

example_command.exe | findstr /C:"string_D  " /C:"string_B  " /C:"string_C  " /C:"string_A  "

Yes, there are two spaces after the string text. I expected the output to be:

string_D
string_B
string_C
string_A

However, I'm getting:

string_A
string_B
string_C
string_D

findstr appears to be sorting the output alphabetically. Can that be disabled? I'd like it to output in the same order I entered it.

I want to do this with standard Windows 7 commands so I can easily distribute it in batch files.

I can separate the strings and run example_command.exe four times but that takes four times as long.

Is this another undocumented feature of findstr?

Was it helpful?

Solution

While it's pretty much running example_command.exe multiple times, this should give you the output you're looking for.

example_command.exe | findstr /C:"string_D  " && example_command.exe | findstr /C:"string_B  " && example_command.exe | findstr /C:"string_C  " && example_command.exe | findstr /C:"string_A  "

However like you said it will take 4 times as long.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top