grep [a-z] producing 1 character
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'm trying to grep for a specific string with two identifiable characters.. example of this is
grep -rhIo '[a-zA-z]@[a-zA-z].com]
input file example:
name:phone:example@example.com
which should theoretically output:
example@example.com
but it will only output
e@e
so some how I need to indicate that a-z can be unlimited length and not just one char
grep regular-expression
add a comment |Â
up vote
1
down vote
favorite
I'm trying to grep for a specific string with two identifiable characters.. example of this is
grep -rhIo '[a-zA-z]@[a-zA-z].com]
input file example:
name:phone:example@example.com
which should theoretically output:
example@example.com
but it will only output
e@e
so some how I need to indicate that a-z can be unlimited length and not just one char
grep regular-expression
The expression[a-zA-Z]
is a pattern which will match exactly one character. If you want zero or more of those, use[a-zA-z]*
].+
will, in an extended regex, match on one or more. So you probably want to use for your pattern:[a-zA-Z]+@[a-zA-z.-]+.[a-z]+
.
â DopeGhoti
Mar 23 at 20:55
I assume you left off the trailing single quote by accident?
â Jeff Schaller
Mar 23 at 21:04
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to grep for a specific string with two identifiable characters.. example of this is
grep -rhIo '[a-zA-z]@[a-zA-z].com]
input file example:
name:phone:example@example.com
which should theoretically output:
example@example.com
but it will only output
e@e
so some how I need to indicate that a-z can be unlimited length and not just one char
grep regular-expression
I'm trying to grep for a specific string with two identifiable characters.. example of this is
grep -rhIo '[a-zA-z]@[a-zA-z].com]
input file example:
name:phone:example@example.com
which should theoretically output:
example@example.com
but it will only output
e@e
so some how I need to indicate that a-z can be unlimited length and not just one char
grep regular-expression
edited Mar 23 at 20:27
Jeff Schaller
31.2k846105
31.2k846105
asked Mar 23 at 20:26
Uni VPS
82
82
The expression[a-zA-Z]
is a pattern which will match exactly one character. If you want zero or more of those, use[a-zA-z]*
].+
will, in an extended regex, match on one or more. So you probably want to use for your pattern:[a-zA-Z]+@[a-zA-z.-]+.[a-z]+
.
â DopeGhoti
Mar 23 at 20:55
I assume you left off the trailing single quote by accident?
â Jeff Schaller
Mar 23 at 21:04
add a comment |Â
The expression[a-zA-Z]
is a pattern which will match exactly one character. If you want zero or more of those, use[a-zA-z]*
].+
will, in an extended regex, match on one or more. So you probably want to use for your pattern:[a-zA-Z]+@[a-zA-z.-]+.[a-z]+
.
â DopeGhoti
Mar 23 at 20:55
I assume you left off the trailing single quote by accident?
â Jeff Schaller
Mar 23 at 21:04
The expression
[a-zA-Z]
is a pattern which will match exactly one character. If you want zero or more of those, use [a-zA-z]*
]. +
will, in an extended regex, match on one or more. So you probably want to use for your pattern: [a-zA-Z]+@[a-zA-z.-]+.[a-z]+
.â DopeGhoti
Mar 23 at 20:55
The expression
[a-zA-Z]
is a pattern which will match exactly one character. If you want zero or more of those, use [a-zA-z]*
]. +
will, in an extended regex, match on one or more. So you probably want to use for your pattern: [a-zA-Z]+@[a-zA-z.-]+.[a-z]+
.â DopeGhoti
Mar 23 at 20:55
I assume you left off the trailing single quote by accident?
â Jeff Schaller
Mar 23 at 21:04
I assume you left off the trailing single quote by accident?
â Jeff Schaller
Mar 23 at 21:04
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I wouldn't even use grep
in the example you posted, it's simple enough to be handled by cut
:
$ echo name:phone:example@example.com | rev | cut -d: -f1 | rev
example@example.com
EDIT:
But if you want grep
it would be something like this:
$ echo name:phone:example@example.com | grep -oE '[a-zA-Z]+@[a-zA-Z]+.com'
example@example.com
Note that +
is used which stands one or more instances
of the previous character in regular expressions and that -E
has to be used with grep for that to work:
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below).
(-E is specified by POSIX.)
Thank you sir for the information, it solved the problem that was occurring :)!
â Uni VPS
Mar 23 at 20:41
Why do you userev
? Why not justcut
the third field?
â wjandrea
Mar 24 at 17:56
In the case the were more fields - withrev
we'll always get the last one.
â Arkadiusz Drabczyk
Mar 24 at 18:54
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I wouldn't even use grep
in the example you posted, it's simple enough to be handled by cut
:
$ echo name:phone:example@example.com | rev | cut -d: -f1 | rev
example@example.com
EDIT:
But if you want grep
it would be something like this:
$ echo name:phone:example@example.com | grep -oE '[a-zA-Z]+@[a-zA-Z]+.com'
example@example.com
Note that +
is used which stands one or more instances
of the previous character in regular expressions and that -E
has to be used with grep for that to work:
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below).
(-E is specified by POSIX.)
Thank you sir for the information, it solved the problem that was occurring :)!
â Uni VPS
Mar 23 at 20:41
Why do you userev
? Why not justcut
the third field?
â wjandrea
Mar 24 at 17:56
In the case the were more fields - withrev
we'll always get the last one.
â Arkadiusz Drabczyk
Mar 24 at 18:54
add a comment |Â
up vote
1
down vote
accepted
I wouldn't even use grep
in the example you posted, it's simple enough to be handled by cut
:
$ echo name:phone:example@example.com | rev | cut -d: -f1 | rev
example@example.com
EDIT:
But if you want grep
it would be something like this:
$ echo name:phone:example@example.com | grep -oE '[a-zA-Z]+@[a-zA-Z]+.com'
example@example.com
Note that +
is used which stands one or more instances
of the previous character in regular expressions and that -E
has to be used with grep for that to work:
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below).
(-E is specified by POSIX.)
Thank you sir for the information, it solved the problem that was occurring :)!
â Uni VPS
Mar 23 at 20:41
Why do you userev
? Why not justcut
the third field?
â wjandrea
Mar 24 at 17:56
In the case the were more fields - withrev
we'll always get the last one.
â Arkadiusz Drabczyk
Mar 24 at 18:54
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I wouldn't even use grep
in the example you posted, it's simple enough to be handled by cut
:
$ echo name:phone:example@example.com | rev | cut -d: -f1 | rev
example@example.com
EDIT:
But if you want grep
it would be something like this:
$ echo name:phone:example@example.com | grep -oE '[a-zA-Z]+@[a-zA-Z]+.com'
example@example.com
Note that +
is used which stands one or more instances
of the previous character in regular expressions and that -E
has to be used with grep for that to work:
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below).
(-E is specified by POSIX.)
I wouldn't even use grep
in the example you posted, it's simple enough to be handled by cut
:
$ echo name:phone:example@example.com | rev | cut -d: -f1 | rev
example@example.com
EDIT:
But if you want grep
it would be something like this:
$ echo name:phone:example@example.com | grep -oE '[a-zA-Z]+@[a-zA-Z]+.com'
example@example.com
Note that +
is used which stands one or more instances
of the previous character in regular expressions and that -E
has to be used with grep for that to work:
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below).
(-E is specified by POSIX.)
edited Mar 23 at 20:41
answered Mar 23 at 20:35
Arkadiusz Drabczyk
7,18521532
7,18521532
Thank you sir for the information, it solved the problem that was occurring :)!
â Uni VPS
Mar 23 at 20:41
Why do you userev
? Why not justcut
the third field?
â wjandrea
Mar 24 at 17:56
In the case the were more fields - withrev
we'll always get the last one.
â Arkadiusz Drabczyk
Mar 24 at 18:54
add a comment |Â
Thank you sir for the information, it solved the problem that was occurring :)!
â Uni VPS
Mar 23 at 20:41
Why do you userev
? Why not justcut
the third field?
â wjandrea
Mar 24 at 17:56
In the case the were more fields - withrev
we'll always get the last one.
â Arkadiusz Drabczyk
Mar 24 at 18:54
Thank you sir for the information, it solved the problem that was occurring :)!
â Uni VPS
Mar 23 at 20:41
Thank you sir for the information, it solved the problem that was occurring :)!
â Uni VPS
Mar 23 at 20:41
Why do you use
rev
? Why not just cut
the third field?â wjandrea
Mar 24 at 17:56
Why do you use
rev
? Why not just cut
the third field?â wjandrea
Mar 24 at 17:56
In the case the were more fields - with
rev
we'll always get the last one.â Arkadiusz Drabczyk
Mar 24 at 18:54
In the case the were more fields - with
rev
we'll always get the last one.â Arkadiusz Drabczyk
Mar 24 at 18:54
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433152%2fgrep-a-z-producing-1-character%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
The expression
[a-zA-Z]
is a pattern which will match exactly one character. If you want zero or more of those, use[a-zA-z]*
].+
will, in an extended regex, match on one or more. So you probably want to use for your pattern:[a-zA-Z]+@[a-zA-z.-]+.[a-z]+
.â DopeGhoti
Mar 23 at 20:55
I assume you left off the trailing single quote by accident?
â Jeff Schaller
Mar 23 at 21:04