Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing arithmetic forms using sed

Tags:

bash

shell

sed

I want to remove ${} among arithmetic form in the file using sed for example abc=$(( ${var}+3 )) to abc=$(( var+3 ))

I'm using positional swapping in sed something like

sed -E 's/(\w+\W\$\(\( ) (\$\{) (\w+) (\}) (.*)/\1 \3 \5/g file.txt'

but it extracts only abc=3 when I use

echo abc=$((( ${var}+3 )) | sed -E 's/(\w+\W\$\(\( ) (\$\{) (\w+) (\}) (.*)/\1 \3 \5/' 

in terminal, just to check if it works all right

and it did nothing on shell script how can I remove only ${} part of the file?

I am using Mac OS and also tried on Ubuntu but it was still the same

like image 683
mangs Avatar asked Jun 27 '26 12:06

mangs


1 Answers

Using sed

$ sed -E 's/\$\{([^}]*)}/\1/' input_file
abc=$(( var+3 ))
like image 168
HatLess Avatar answered Jul 01 '26 21:07

HatLess



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!