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
Example-2: Trim string data using `sed` commandUse sed 's/^ *//g', to remove the leading white spaces. There is another way to remove whitespaces using `sed` command. The following commands removed the spaces from the variable, $Var by using `sed` command and [[:space:]]. $ echo "$Var are very popular now."
bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc.
Also try this bash only oneliner as an alternative:
s="this-is-a-{test}file"
echo ${s/\{test\}/}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With