Loading...

Remove a word from a string bash

Answer #1 100 %

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
Answer #2 100 %

Also try this bash only oneliner as an alternative:

s="this-is-a-{test}file"
echo ${s/\{test\}/}
Tags: bash

You’ll also like:


© 2022 CodeForDev.com -