diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2019-07-17 04:24:21 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2019-07-17 04:24:21 +0000 |
commit | eb035a8d91662acbd8d08a8c195ea92714cf46bc (patch) | |
tree | cb88366a0f1d939c5612499278a4d10e9fd26b2d | |
parent | 83e07bbebc46cc6237d5c5728cb976772d51c97a (diff) |
when combining -o and -b, print the byte offset of the pattern, not line.
originally from chrisz
-rw-r--r-- | usr.bin/grep/grep.1 | 10 | ||||
-rw-r--r-- | usr.bin/grep/util.c | 5 |
2 files changed, 9 insertions, 6 deletions
diff --git a/usr.bin/grep/grep.1 b/usr.bin/grep/grep.1 index 3085a02dbca..b77011981ed 100644 --- a/usr.bin/grep/grep.1 +++ b/usr.bin/grep/grep.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: grep.1,v 1.45 2017/12/10 09:17:24 jmc Exp $ +.\" $OpenBSD: grep.1,v 1.46 2019/07/17 04:24:20 tedu Exp $ .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -28,7 +28,7 @@ .\" .\" @(#)grep.1 8.3 (Berkeley) 4/18/94 .\" -.Dd $Mdocdate: December 10 2017 $ +.Dd $Mdocdate: July 17 2019 $ .Dt GREP 1 .Os .Sh NAME @@ -131,8 +131,10 @@ and .Fl C options. .It Fl b -The offset in bytes of a matched pattern is -displayed in front of the respective matched line. +Each output line is preceded by its position (in bytes) in the file. +If option +.Fl o +is also specified, the position of the matched pattern is displayed. .It Fl C Ns Oo Ar num Oc , Fl -context Ns Op = Ns Ar num Print .Ar num diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index bfd2bc3cef0..84db8bee013 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.59 2019/01/23 23:00:54 tedu Exp $ */ +/* $OpenBSD: util.c,v 1.60 2019/07/17 04:24:20 tedu Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -651,7 +651,8 @@ printline(str_t *line, int sep, regmatch_t *pmatch) if (bflag) { if (n) putchar(sep); - printf("%lld", (long long)line->off); + printf("%lld", (long long)line->off + + (pmatch ? pmatch->rm_so : 0)); ++n; } if (n) |