[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tabbed & pretty output
From: |
Tony Abou-Assaleh |
Subject: |
Re: Tabbed & pretty output |
Date: |
Sun, 23 Mar 2008 02:47:49 -0300 |
User-agent: |
Thunderbird 2.0.0.12 (Macintosh/20080213) |
Jonatan Wallmander wrote:
|Hi guys!
I downloaded, compiled and tried the latest grep, 2.5.3.
I'd really like this kind of output: (view this mail with fixed-width
font please)
----
path1/path2/path3/file.ext: foo bar baz fruu muu koo loo boo poo hello
||koo loo boo poo hello
----
But grep goes:
----
||path1/path2/path3/file.ext: foo bar baz fruu muu koo loo boo poo hello
||koo loo boo poo hello
----
Which is more difficult to read IMO, it would totally rock to have the
first kind of output available..
It would place more emphasis on the files.
I guessed the -T parameter would do this, but on my fedora it doesn't
work, or did I misunderstand -T ?
From the grep docs:
-T, --initial-tab
Make sure that the first character of actual line content lies
on a tab stop, so that the alignment of tabs looks normal.
So it only affects on which column of your terminal the word 'foo' in
your example would start. Currently, grep doesn't wrap lines for you; it
is done by your terminal.
So this is either a bug report or a feature request :)
What you're suggesting is essentially defining some environment variable
where you specify how many chars to output per line (similar to COLUMNS
for 'ps') and apply the -T behaviour to wrapped lines. The following
perl script does something similar to what you suggest (in a very
primitive way):
--
# Usage: wrap.pl cols grep_output
$cols = shift;
while (<>) {
/^([^:]*:)(.*)$/;
$head = $1;
$tail = $2;
$head_len = length($head);
$tail_cols = $cols - $head_len;
print $head . substr($tail, 0, $tail_cols) . "\n";
$tail = substr($tail, $tail_cols);
$head =~ s/./ /g;
while ($tail ne "") {
print $head . substr($tail, 0, $tail_cols) . "\n";
$tail = substr($tail, $tail_cols);
}
}
--
Use it as:
$ grep -H mypattern *.txt | perl wrap.pl 30
One can probably write a more elegant formatter in awk ;O) This script
is provided for illustration only; it doesn't do any error checking and
will not work in all cases.
Cheers,
TAA
--
Tony Abou-Assaleh
Email: address@hidden
Web site: http://tony.abou-assaleh.net