This question already has an answer here:

I'm on Ubuntu 16.04

Trying: grep '.*' file1

Output: file nu-mber o-ne second string

Trying: grep '.+' file1

Output is absent

Why plus is not working?

marked as duplicate by Gilles, Satō Katsura, don_crissti, countermode, Jeff Schaller Oct 14 '16 at 15:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You need to tell grep you're using an extended regular expression:

grep -E '.+' file1

The standard Basic Regular Expression (as used by grep without -E) equivalent of the Extended Regular Expression + operator is \{1,\} though some implementations (like GNU's) also recognise \+ for that as an extension (and you can always use ..*).

(Note that in this particular case grep -E .+ is equivalent to grep -E . as you're looking for substrings matching the regex when not using the -x option. On many systems egrep is provided as an equivalent command to grep -E, but as Graeme points out this is obsolete.)


With GNU grep (default on Ubuntu) you can also enable extended behavior with a backslash. Eg:

grep '.\+' file1

I believe + is an extended regular expression metacharacter. Try using egrep.

Not the answer you're looking for? Browse other questions tagged or ask your own question.