8

I was requested to make a shell script to check for simple mistakes in files. I wanted to find, for each line if

(regex:) "[ ]\t" ever happens.

The problem is that grep is ignoring the \ and is taking "t" as a literal. I also tried writting the characters themselves in a file and asking grep to read it but it didn't work. Is there a way to find for the regex " \t" in files using any of the usual linux tools (like grep)?

I already tried:

grep -E --ignore-case --line-number --with-filename --file="b" file

(b contains: " ") and also:

grep -E --ignore-case --line-number --with-filename --regexp=" [\t]" file
brunoais
  • 5,392
  • 8
  • 34
  • 58

2 Answers2

16

You can use C-style string $'...'

grep $'\t' file.txt

Or sed:

sed -n '/\t/p' file.txt
kev
  • 146,428
  • 41
  • 264
  • 265
5

You can use perl regex with --perl-regex option like

 grep --perl-regex "\t"