bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#44983: Truncate long lines of grep output


From: Jean Louis
Subject: bug#44983: Truncate long lines of grep output
Date: Thu, 10 Dec 2020 00:43:23 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

Also see this:

https://www.topbug.net/blog/2016/08/18/truncate-long-matching-lines-of-grep-a-solution-that-preserves-color/

,----
| For the example above, the following command should print only 20
| characters before and after the searching keyword (This requires GNU
| grep. If you are on Mac OS X and using the BSD grep, please consider
| following this article to install GNU grep):
| 
| grep -oE '.{0,20}jQuery.{0,20}' bootstrap.min.js
`----

where I get this:

grep -o --color -nH --null -E  ".{0,20}setting.{0,20}" tmp-2020-11-26-01:3*
tmp-2020-11-26-01:32:17986egO3: supported, but its setting does not have prior

Grep finished with 1 match found at Thu Dec 10 00:42:21

from this line long made-up line:

‘--color[=WHEN]’ ‘--colour[=WHEN]’ Surround the matched (non-empty) strings, 
matching lines, context lines, file names, line numbers, byte offsets, and 
separators (for fields and groups of context lines) with escape sequences to 
display them in color on the terminal.  The colors are defined by the 
environment variable ‘GREP_COLORS’ and default to 
‘ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36’ for bold red matched text, 
magenta file names, green line numbers, green byte offsets, cyan separators, 
and default terminal colors otherwise. The deprecated environment variable 
‘GREP_COLOR’ is still supported, but its setting does not have priority; it 
defaults to ‘01;31’ (bold red) which only covers the color for matched text. 
WHEN is ‘never’, ‘always’, or ‘auto’. ‘-L’ ‘--files-without-match’ Suppress 
normal output; instead print the name of each input file from which no output 
would normally have been printed.  The scanning of each file stops on the first 
match. ‘-l’ ‘--files-with-matches’ Suppress normal output; instead print the 
name of each input file from which output would normally have been printed.  
The scanning of each file stops on the first match.  (‘-l’ is specified by 
POSIX.)

and that solves the problem of truncating long lines.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]