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

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

Re: grep feature request: show column numbers


From: Stephane Chazelas
Subject: Re: grep feature request: show column numbers
Date: Mon, 13 Dec 2004 13:21:59 +0000
User-agent: Mutt/1.5.6i

On Mon, Dec 13, 2004 at 12:52:27PM +1100, Martin Pool wrote:
> It would be nice if GNU grep had an option to show the column number
> of the start of the first match on each line, so that emacs grep-mode
> can put the cursor exactly on the match, not just at the start of the
> line.  Something like this:
> 
> % grep -nH --column GNU /etc/issue
> /etc/issue:1:8:Debian GNU/Linux 3.1 \n \l
> 
[...]

That's a job for awk:

gawk -vOFS=: 'n = match($0, /GNU/) { print FILENAME, FNR, n, $0 }
             ' /etc/issue

You could write that wrapper script:

#! /usr/bin/gawk -f
BEGIN {
  pattern = ARGV[1]
  delete ARGV[1]
  OFS=":"
}
n = match($0, pattern) { print FILENAME, FNR, n, $0 }


$ script.awk GNU /etc/issue
/etc/issue:1:8:Debian GNU/Linux 3.1 \n \l

-- 
Stéphane





reply via email to

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