部分文字列を含むすべての単語を見つけ、別の行に表示します。

部分文字列を含むすべての単語を見つけ、別の行に表示します。

部分文字列を含むすべての単語を見つけて別の行に表示するには?

私は次の行を持っています:

john_ford peter_smith john_stone albert_brown john_rice john_harris lewis coll

全部見せたいjohn_

私が使用している場合grep -o

echo "john_ford peter_smith john_stone albert_brown john_rice john_harris lewis coll" | grep -o john_

結果:

john_
john_
john_
john_

しかし、私が望む結果は次のとおりです。

john_ford
john_stone
john_rice
john_harris

どうやって入手できますか? 、awkなどのツールを使用する必要がありますか?

ベストアンサー1

解決策:grep -o '\b'john_'\w*'

echo "john_ford peter_smith john_stone albert_brown john_rice john_harris lewis coll" |
  grep -o '\b'john_'\w*'

おすすめ記事