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?
+3
A:
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:
-o, --only-matching Show only the part of a matching line that matches PATTERN.
..or -c
:
-c, --count Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines.
Ether
2010-01-09 20:21:56
A:
Pipe your results thru cut
. I'm also considering adding a --cut switch so you could say --cut=80 and only get 80 columns.
Andy Lester
2010-01-09 21:19:54
What if the part that matches is not in the first 80 characters?
Ether
2010-01-09 22:08:02