I want to add parenthesis to all words I used
sed \'s/[a-z]*/(&)/g\'
inputfile.txt
hola crayola123456
abc123456
>
The reason is that you are using a regex that can match an empty string. [a-z]*
can match any empty space before a char since regex "sees" (i.e. checks) these positions. You need to replace the *
(matching zero or more occurrences) with +
quantifier (to match one or more characters).
Here is an example of how this can be implemented in GNU sed:
echo "hola crayola123456" | sed 's/[a-z]\+/(&)/g'
See the online demo
On Mac, as per anubhava's comment, you need to use E
option and use an unescaped +
:
echo "hola crayola123456" | sed -E 's/[a-z]+/(&)/g'