Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在文本文件中有以下几行
myname aaa age 22 age 23 myname bbb
如何使用 linux grep命令找到myname之后的单词。?
我希望输出是 myname 之后的单词( aaa 和 bbb )
$ grep -Po '(?<=myname\s)\w+' inputFile
$ grep -o "myname [[:alnum:]]\+" /tmp/sample | cut -f2 -d' ' aaa bbb
解决方案sed:
sed
sed -n '/myname/{s/.*myname \([^ ]*\).*/\1/;p}'