using linux grep with look ahead regexp
Solution 1:
Without grep -P
, you can use grep + cut
:
grep -oE '[^@ ]+@ex\.com' list.txt | cut -d@ -f1
userone
usertwo
userthree
With gnu grep
:
grep -oP '[^@ ]+(?=@ex\.com)' list.txt
userone
usertwo
userthree