Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
616 views
in Technique[技术] by (71.8m points)

unix - How to grep for the whole word

I am using the following command to grep stuff in subdirs

find . | xargs grep -s 's:text'

However, this also finds stuff like <s:textfield name="sdfsf"...../>

What can I do to avoid that so it just finds stuff like <s:text name="sdfsdf"/>

OR for that matter....also finds <s:text somethingElse="lkjkj" name="lkkj"

basically s:text and name should be on same line....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You want the -w option to specify that it's the end of a word.

find . | xargs grep -sw 's:text'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...