[BusyBox 0000999]: [PATCH] grep option -o

bugs at busybox.net bugs at busybox.net
Wed Aug 16 22:53:06 UTC 2006


The following issue has been SUBMITTED. 
====================================================================== 
http://busybox.net/bugs/view.php?id=999 
====================================================================== 
Reported By:                jac_goudsmit
Assigned To:                BusyBox
====================================================================== 
Project:                    BusyBox
Issue ID:                   999
Category:                   New Features
Reproducibility:            N/A
Severity:                   feature
Priority:                   normal
Status:                     assigned
====================================================================== 
Date Submitted:             08-16-2006 15:53 PDT
Last Modified:              08-16-2006 15:53 PDT
====================================================================== 
Summary:                    [PATCH] grep option -o
Description: 
Here's a patch to findutils/grep.c (based on the 1.2.1 release) that
implements the -o option ("print pattern only"). 

For example, the following command lists all the options in the kernel
config file:

  busybox grep -o "CONFIG_[^=]*" /usr/src/linux/.config

I did some brief testing and found one issue compared to GNU grep (2.5.1):
when -o is used in combination with -v, the modified busybox grep will
print empty lines whereas GNU grep prints nothing. When -o is used with -v
and -n, the modified busybox grep prints line numbers followed by line
feeds, whereas GNU grep prints line numbers in a long stream without line
feeds. However the usage of -o in combination with -v is so unlikely that
I don't think it's worth fixing.

For example: when running this command:

  grep -ov CONFIG /usr/src/linux/.config

GNU grep will produce no output, busybox produces a lot of empty lines.
Another example: when running this command:

  grep -ovn CONFIG /usr/src/linux/.config

GNU grep will produce a long list of line numbers in one stream:

  1:2:3:4:5: ... (etc)

Busybox produces a lot of empty lines with line numbers:

  1:
  2:
  3:
  4:
  5:
  ... (etc)

A pretty simple patch that has helped me in my project which is to build a
uClibc/BusyBox-based install of Gentoo. Gentoo's rc scripts use grep -o in
a lot of places and it was really a lot easier to modify the grep.c code
than to manually replace all the occurrences of grep -o by something like
sed -n "s/something\(${1}\)something/\1/gp".

====================================================================== 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
08-16-06 15:53  jac_goudsmit   New Issue                                    
08-16-06 15:53  jac_goudsmit   Status                   new => assigned     
08-16-06 15:53  jac_goudsmit   Assigned To               => BusyBox         
08-16-06 15:53  jac_goudsmit   File Added: grep-o.patch                     
======================================================================




More information about the busybox-cvs mailing list