0

when I am using the code in my windows CMD it is not giving me any output.

I am using findstr -E ^[0-9]{3}$ and it does not provide the expected output.

This is a sample file:

834
519
4874
5
89
45687
25
645
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
nishant gupta
  • 15
  • 1
  • 4

1 Answers1

0

Windows findStr is not grep, you need to use

findstr /r /c:"^[0-9][0-9][0-9]$" test.txt

The /r option makes findStr search for a "regex" pattern and /c:"..." uses the specified text as a literal search string.

Since the regex features findStr supports are very limited, you can't use {3}, you need to repeat the [0-9] thrice. Test:

C:\>findstr /r /c:"^[0-9][0-9][0-9]$" test.txt
834
519
645

Note: to make it extract 645, I had to make sure there is a trailing linebreak after this last line in the test.txt file.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563