Horje
sed with variable Code Example
sed replace with variable
Just concatenate var '"$var"' to replace values string in sed command:
$ sed -i 's/string_to_replace/'"$var"'/g' file_to_replace.txt
sed with variable
sed -i "s/$var1/ZZ/g" "$file"
bash sed with variable
# If you want to store your regex in a bash variable 
# and use it in sed, you might need the following
BASE_REGEX="[0-9]{4}\.[0-9]+"
REGEX_ESCAPED=$(sed 's/[}{)(+]/\\&/g; s/\^/\\^/g' <<< "$BASE_REGEX")

# One variable can be used with sed
sed -i "s/${REGEX_ESCAPED}/REPLACEMENT/g" file.txt
# The other can be used with bash internal regex operator
if [[ "2022.42" =~ ^${BASE_REGEX}$ ]]
then
	echo 'Matches !'
fi




Shell

Related
ubuntu increase volume Code Example ubuntu increase volume Code Example
curl form data Code Example curl form data Code Example
how to kill process by command bu username Code Example how to kill process by command bu username Code Example
bash script change directory run a command Code Example bash script change directory run a command Code Example
git fatal bad revision cherry-pick Code Example git fatal bad revision cherry-pick Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11