I want to grep the shortest match and the pattern should be something like:
...
...
...
... mean
Sorry I am 9 years late, but this might work for the viewers in 2020.
So suppose you have a line like "Hello my name is Jello"
.
Now you want to find the words that start with 'H'
and end with 'o'
, with any number of characters in between. And we don't want lines we just want words. So for that we can use the expression:
grep "H[^ ]*o" file
This will return all the words. The way this works is that: It will allow all the characters instead of space character in between, this way we can avoid multiple words in the same line.
Now you can replace the space character with any other character you want.
Suppose the initial line was "Hello-my-name-is-Jello"
, then you can get words using the expression:
grep "H[^-]*o" file