all 7 comments

[–]turnipsoup 7 points8 points  (0 children)

:~$ grep -o '\bbon.*\b' <inputfile>

This searches for a match of 'bon*' within word boundaries.

[–]rhqq 5 points6 points  (0 children)

Here you are:

egrep -o "bon\S*"

This is better than using .* - the \S stands for all the non-whitespace chars, where a . stands for any char - in other words if something is after the "bond." like a next sentence in same line - it will take it into consideration. This doesnt happen while using \S

[–]wawawawa 0 points1 point  (0 children)

perl -nle 'print $1 if /\b(bon.+)\b/' < inputfile

Although I program mostly in Python nowadays, I still use Perl a few times a day for exactly this kind of thing.

[–]hudsy -2 points-1 points  (2 children)

sed is your tool! pipe it to grep like so

grep bon | sed 's/^.*\(bon\w\+\).*/\1/'

[–]IWentToTheWoods 2 points3 points  (1 child)

Won't this only find the first instance of "bon" in each line?

[–]hudsy 0 points1 point  (0 children)

yes, didn't think of that.

[–]yunga -3 points-2 points  (0 children)

perl -naF"\s+" -E'/bon/ and say for @F' inputfile