Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

sed replace number of variable length

Just use one of following commands for replacing a number of:
sed "s/[0-9]//" f.txt	#One single digit as 1
sed "s/[0-9]+//" f.txt #Further digits as 837, specifying match repetition "+"
sed "s/[0-9+.[0-9]+]//" file.txt #Float type with decimals
Comment

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
Comment

sed replace number

Just use one of following commands for replacing a number of:
sed "s/[0-9]//" f.txt	#One single digit as 1
sed "s/[0-9]+//" f.txt #Further digits as 837, specifying match repetition "+"
sed "s/[0-9]+.[0-9]+]//" file.txt #Float type with decimals
Comment

sed replace with variable

sed -i "s/$var1/ZZ/g" "$file"
Comment

sed replace with variable

For 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'
Comment

sed replace with variable

Use double quotes to make the shell expand variables while preserving whitespace:

sed -i "s/$var1/ZZ/g" "$file"
Comment

PREVIOUS NEXT
Code Example
Shell :: how to set global github username and password in git 
Shell :: install cherrypy 
Shell :: install latest i18next version 
Shell :: List files and sort by date and time in Linux 
Shell :: git create a new branch from current branch 
Shell :: create folder in terminal 
Shell :: add more changes to same commit 
Shell :: install kazam screencaster ubuntu 
Shell :: how to start nginx in ubuntu 
Shell :: merge two branches from different repositories 
Shell :: how to install xdebug 
Shell :: copy directory 
Shell :: Re-run cmake with a different source directory. 
Shell :: how to install tesseract in other language in linux 
Shell :: clone a particular branch 
Shell :: powershell script enable tls 1.2 
Shell :: wsl2 settings 
Shell :: ubuntu install gnote 
Shell :: install cassandra ubuntu 
Shell :: arch linux pacman cannot install 
Shell :: permission denied /dev/ttyusb0 
Shell :: set github ssh key 
Shell :: install drush on ubuntu 18.04 
Shell :: kill cron proccess ubuntu terminal 
Shell :: install composer debian 
Shell :: git revert back to specific commit 
Shell :: scp remote to local 
Shell :: install mpfr ubuntu 
Shell :: bash get current process id 
Shell :: check pip library path ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =