Ubuntu – How to make grep display only the matching regexp

grepregex

I am trying to find data from files using grep, but grep usually prints out the filename as well as the line where the term is found.

In this case, I am looking for a special regexp and I want grep to print all items matching the regexp, not the line or the filename. In other words, I want to see only the matched regular expression.

Best Answer

With GNU grep, that's the -o option possibly combined with -h to suppress the filename.