Reputation: 29
Using sed commands
In the following sentence add [] around words starting with s and containing e and t in any order “subtle exhibit asset sets tests site”.
Here is what I have so far (see code section)
$ echo "subtle exhibit asset sets tests site." | sed 's/^s\ "et"/[]/g'
Upvotes: 0
Views: 105
Reputation: 203502
This may be what you're looking for, using GNU sed for -E
so we don't need to escape the (
and )
capture group delimiters and can use |
for "or", and \w
shorthand for word-constituent characters and \<
word boundary:
$ echo 'subtle exhibit asset sets tests site.' |
sed -E 's/\<s\w*(e\w*t|t\w*e)\w*/[&]/g'
[subtle] exhibit asset [sets] tests [site].
Upvotes: 1