'Add bracket around a string that match this pattern
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'
Solution 1:[1]
Using GNU sed
$ sed 's/\<s\([a-z]*\?e[a-z]*\?t[a-z]*\?\|[a-z]*\?t[a-z]*\?e[a-z]*\?\)[^ ]*\>/[&]/g' input_file
[subtle] exhibit asset [sets] tests [site].
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
