1

I need to find all lines in a text file that start with a tab character.

I tried this command:

findstr /B /R "\t" test.txt

But it doesn't print any lines.

I also tried with grep.exe (taken from UnxUtils):

grep -E "^\t" test.txt

This also doesn't print any lines.

2
  • Try escaping the \ - findstr /B /R "\\t" test.txt
    – DavidPostill
    Commented Jun 3, 2023 at 0:56
  • @DavidPostill I've just tried that, but it doesn't work either.
    – Mercalli
    Commented Jun 3, 2023 at 1:04

2 Answers 2

3

I need to find all lines in a text file that start with tab.

You need to start cmd with the /f:on parameter. This changes the file completion character to ctrlf and frees up tab so you can use it on the command line.

cmd /f:on

See: CMD.exe (Command Shell) - Windows CMD - SS64.com

You also need to use findstr with /c not /r

Example:

F:\test>type tab.txt
        this line starts with a tab
        this line starts with spaces
F:\test>findstr /b /c:" " tab.txt
        this line starts with a tab

where: the character in quotes above is tab not space.

3

For those of us who use Powershell, it can be achieve with the cmdlet:

 Select-String test.txt -Pattern "^\t.+"

This will show the lines and indicates the line number. If you don't want to see the line numbers, use the following:

 Select-String test.txt -Pattern "^\t.+" -Raw

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .