Reputation: 145
I have some random strings. I am trying to print only the whole words with the following:
grep -ioh "\w*ice\w*"
This works fine but it seems to don't showing the symbols but only letters. I'd like the wildcards to allow any symbols but the spaces. Is this something possible?
To better explain, the above code in a string like:
The cat is very-nice shows only "nice" while I'd like to have "very-nice"
Upvotes: 2
Views: 1338
Reputation: 626927
You may use
grep -ioh "\S*ice\S*"
Or
grep -ioh "[^[:space:]]*ice[^[:space:]]*"
The [^[:space:]]
(or \S
) match any char but a whitespace char.
See the grep
online demo:
grep -ioh "\S*ice\S*" <<< "The cat is very-nice"
## => very-nice
Upvotes: 2