Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

sed replace in file

sed -i 's/foo/bar/g' hello.txt
Comment

replace using sed

#on my mac
sed -i -e 's/old-text/new-text/g' text.txt
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

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 :: jupyter command install 
Shell :: windows search multiple file types 
Shell :: bash manual 
Shell :: ubuntu change primary group 
Shell :: nano show line numbers 
Shell :: apt install package version 
Shell :: git pull rebase command 
Shell :: check difference between two branches git 
Shell :: pip install six 
Shell :: sign a commit after push 
Shell :: online centos terminal 
Shell :: find resolution of image terminal linux 
Shell :: move all subfolders to parent folder linux 
Shell :: if statement bash 
Shell :: install nginx on ec2 
Shell :: install font in react native 
Shell :: doxygen install 
Shell :: bash script get last position of character in string 
Shell :: how to install face_recognition with conda 
Shell :: abbreviated stat for git 
Shell :: docker input device is not a tty 
Shell :: bash escape all special characters 
Shell :: commit with git 
Shell :: git combine two branches into third 
Shell :: docker repository 
Shell :: pacman command on arch 
Shell :: add user with sudoer centos 
Shell :: git add . 
Shell :: sudo -s su root in one line 
Shell :: Use linux not Windows 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =