3

I'm trying to use Grep to find a string with Tabs, Carriage Returns, & New Lines. Any other method would be helpful also.

grep -R "\x0A\x0D\x09<p><b>Site Info</b></p>\x0A\x0D\x09<blockquote>\x0A\x0D\x09\x09<p>\x0A\x0D\x09</blockquote>\x0A\x0D</blockquote>\x0A\x0D<blockquote>\x0A\x0D\x09<p><b>More Site Info</b></p>" *
user3851589
  • 75
  • 1
  • 1
  • 7

2 Answers2

3

From this answer

If using GNU grep, you can use the Perl-style regexp:

$ grep -P '\t' *

Also from here

Use Ctrl+V, Ctrl+M to enter a literal Carriage Return character into your grep string. So:

grep -IUr --color "^M"

will work - if the ^M there is a literal CR that you input as I suggested.

If you want the list of files, you want to add the -l option as well.

Community
  • 1
  • 1
Srini V
  • 11,045
  • 14
  • 66
  • 89
0

Quoting this answer:

Grep is not sufficient for this operation.

pcregrep, which is found in most of the modern Linux systems can be used ...

Bash Example

$ pcregrep -M "try:\n    fro.*\n.*except" file.py

returns

try:
    from tifffile import imwrite
except (ModuleNotFoundError, ImportError):
Markus Dutschke
  • 9,341
  • 4
  • 63
  • 58