6

I would like to use grep -o, but in git bash there is no -o option. Is there a way to get full working grep in git bash, just like it's in linux bash shell?

siulkilulki
  • 1,054
  • 1
  • 10
  • 18

2 Answers2

1

There is no -o flag for grep http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html

You can use sed instead

Community
  • 1
  • 1
Prateek Batla
  • 1,972
  • 1
  • 11
  • 8
  • 2
    There is one for [GNU grep](http://www.gnu.org/software/grep/manual/grep.html#General-Output-Control), but it's a GNU extension. – Benjamin W. Jan 08 '16 at 07:07
0

There is an open issue for that on Github (even though it's under "nvm"). User UltCombo posted a workaround. Quoting:

Open <Git install directory>/bin and overwrite grep.exe with a more up to date version. I found two alternatives that provide -o support:

  • GnuWin32's grep 2.5.4 (link).
  • ezwinports' grep 2.10 (link). Note: You also have to extract libprce-0.dll in the same folder as grep.

Though ezwinports' grep port is much more up to date, I can't say whether any of these will cause stability/compatibility issues. I haven't found any issues yet, but use it at your own risk.

Marking this Community Wiki because it's really somebody else's work.

Alternatively, get the pretty awesome MSYS2 and enjoy full grep and co.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116