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
just use grep "<Ctrl+V><TAB>" , it works (if first time: type grep " then press Ctrl+V key combo, then press TAB key, then type " and hit enter, voilà!)
The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.
The -n ( or --line-number ) option tells grep to show the line number of the lines containing a string that matches a pattern. When this option is used, grep prints the matches to standard output prefixed with the line number.
To also show you the lines before your matches, you can add -B to your grep. The -B 4 tells grep to also show the 4 lines before the match. Alternatively, to show the log lines that match after the keyword, use the -A parameter. In this example, it will tell grep to also show the 2 lines after the match.
You can use C-style string $'...'
grep $'\t' file.txt
Or sed
:
sed -n '/\t/p' file.txt
You can use perl regex with --perl-regex
option like
grep --perl-regex "\t"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With