grep [a-z] producing 1 character

The name of the pictureThe name of the pictureThe name of the pictureClash 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







share|improve this question






















  • 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














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







share|improve this question






















  • 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












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







share|improve this question














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









share|improve this question













share|improve this question




share|improve this question








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
















  • 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










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.)





share|improve this answer






















  • 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











  • In the case the were more fields - with rev we'll always get the last one.
    – Arkadiusz Drabczyk
    Mar 24 at 18:54










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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.)





share|improve this answer






















  • 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











  • In the case the were more fields - with rev we'll always get the last one.
    – Arkadiusz Drabczyk
    Mar 24 at 18:54














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.)





share|improve this answer






















  • 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











  • In the case the were more fields - with rev we'll always get the last one.
    – Arkadiusz Drabczyk
    Mar 24 at 18:54












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.)





share|improve this answer














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.)






share|improve this answer














share|improve this answer



share|improve this answer








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 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
















  • 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











  • In the case the were more fields - with rev 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












 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay