giri
giri

Reputation: 21

Tighter word boundary with grep -w

[root]grep -w "/opt/VRTSodm/lib/libodm64.so" PACKAGE/VRTSodm_f2
/opt/VRTSodm/lib/libodm64.so -r-xr-xr-x
/opt/VRTSodm/lib/libodm64.so.1 -r-xr-xr-x

I want the output as a first string only

Upvotes: 0

Views: 1392

Answers (3)

user1019830
user1019830

Reputation:

Use the -o option for that. It will print only the matched part of the line:

grep -o '/opt/VRTSodm/lib/libodm64\.so\.1\?' your_file

Upvotes: 1

tripleee
tripleee

Reputation: 189628

The -w option merely requires the match to be bounded by nonalphabetics. If you have stricter requirements, you need to specify them explicitly.

Because plain grep does not support grouping and alternation out of the box, I use grep -E (aka egrep) here:

grep -E '(^|[[:space:]])/opt/VRTSodm/lib/libodm64.so([[:space:]]|$)' PACKAGE/VRTSodm_f2

Upvotes: 1

John Zwinck
John Zwinck

Reputation: 249394

You can simply add a space at the end of your expression, and it will work for the example you gave.

Upvotes: 0

Related Questions