使用 linux grep 和前瞻性正则表达式
using linux grep with look ahead regexp
我在 txt 文件中有字符串
cat list.txt
userone@ex.com, usertwo@ex.com, userthree@ex.com
我想打印每个用户登录 w/o @ex.com 每一个新行并尝试使用正则表达式 linux grep
grep -oe '[a-z](?=@ex.com,)' list.txt
但是没有任何反应,为什么?它将像:
userone
usertwo
userthree
谢谢。
没有grep -P
,你可以使用grep + cut
:
grep -oE '[^@ ]+@ex\.com' list.txt | cut -d@ -f1
userone
usertwo
userthree
与gnu grep
:
grep -oP '[^@ ]+(?=@ex\.com)' list.txt
userone
usertwo
userthree
我在 txt 文件中有字符串
cat list.txt
userone@ex.com, usertwo@ex.com, userthree@ex.com
我想打印每个用户登录 w/o @ex.com 每一个新行并尝试使用正则表达式 linux grep
grep -oe '[a-z](?=@ex.com,)' list.txt
但是没有任何反应,为什么?它将像:
userone
usertwo
userthree
谢谢。
没有grep -P
,你可以使用grep + cut
:
grep -oE '[^@ ]+@ex\.com' list.txt | cut -d@ -f1
userone
usertwo
userthree
与gnu grep
:
grep -oP '[^@ ]+(?=@ex\.com)' list.txt
userone
usertwo
userthree