I want to run ack or grep on HTML files that often have very long lines. I don't want to see very long lines that wrap repeatedly. But I do want to see just that portion of a long line that surrounds a string that matches the regular expression. How can I get this using any combination of Unix tools?
Unix – How to truncate long matching lines returned by grep or ack
ackgrepunix
Related Topic
- Can grep show only words that match search pattern
- Linux – How to grep recursively
- Git – How to grep (search) committed code in the Git history
- Regex – Negative matching using grep (match lines that do not contain foo)
- Linux – How to exclude directories from grep -R
- Linux – How to use grep to show just filenames on Linux
- How to “grep” for a filename instead of the contents of a file?
- How to grep recursively, but only in files with certain extensions
Best Answer
You could use the grep option
-o
, possibly in combination with changing your pattern to".{0,10}<original pattern>.{0,10}"
in order to see some context around it:..or
-c
: