9

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
  • 6,258
  • 8
  • 39
  • 59

2 Answers2

17

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

grep $'\t' file.txt

Or sed:

sed -n '/\t/p' file.txt
kev
  • 155,172
  • 47
  • 273
  • 272
7

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

 grep --perl-regex "\t"