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?
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?
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.)
egrep
is considered to be obsolete, so grep -E
is preferred - http://pubs.opengroup.org/onlinepubs/7908799/xcu/egrep.html. Not that there is any sign of it disappearing.
– Graeme
Oct 14 '16 at 11:13
With GNU grep (default on Ubuntu) you can also enable extended behavior with a backslash. Eg:
grep '.\+' file1