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.txtFor using match in sed replacement, just border it with '\(' and '\)':
echo Before123 | sed 's/Before\([0-9]*\)/\1After/g'
123After # number is matched withtin '\( \)' and replaced in '\1'
Example with 2 match replacements
echo a_b | sed 's/\(^.*\)_\(.*$\)/first is \1 and \2 is after/g'Use double quotes to make the shell expand variables while preserving whitespace:
sed -i "s/$var1/ZZ/g" "$file"
Also in C++:
- ubuntu install yarn
- copy files from another branch git
- What causes a defunct process on the Linux system and how can you avoid it?
- where is fish shell installed ubuntu
- less in linux
- git merge master into branch
- install a file from internet with command prompt
- how to install protractor
- command to wrap html
- how to make conda to use global packages
- cd in linux
- elixir continuous integration workflow in github
- laravel remote: error: unable to unlink old 'public/.htaccess': Permission denied
- laravel generate key
- heroku create with name
- powershell change directory with space
- How many CPUs and memory do you allocate to your Linux machine?
- decompress bz2
- fatal: 'origin' does not appear to be a git repository
- gitignore is not working
- redux logger
- how to install laravel
- tmux split-window leave open
- install dot-prop