Reputation: 468
I have the string
file="this-is-a-{test}file"
I want to remove {test}
from this string.
I used
echo $file | sed 's/[{][^}]*//'
but this returned me
this-is-a-}file
How can I remove }
too?
Thanks
Upvotes: 10
Views: 36275
Reputation: 6409
Also try this bash only oneliner as an alternative:
s="this-is-a-{test}file"
echo ${s/\{test\}/}
Upvotes: 17
Reputation: 786091
You can use sed
with correct regex:
s="this-is-a-{test}file"
sed 's/{[^}]*}//' <<< "$s"
this-is-a-file
Or this awk:
awk -F '{[^}]*}' '{print $1 $2}' <<< "$s"
this-is-a-file
Upvotes: 11