Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

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
Comment

sed with variable

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

PREVIOUS NEXT
Code Example
Shell :: odoo docker 
Shell :: git create local branch 
Shell :: add dir to your path kali 
Shell :: best terminal for ubuntu 
Shell :: install react Spinner 
Shell :: upload directory ssh to remote 
Shell :: how to install nodemon in project 
Shell :: git delete all remote branch except master 
Shell :: multi line comment in shell script 
Shell :: start nginx in terminal 
Shell :: grep recursive filename matching 
Shell :: ubuntu gui manager 
Shell :: ignore something on github 
Shell :: wget mac robot 
Shell :: command to list hardware in linux 
Shell :: nginx disable site 
Shell :: rename file powershell 
Shell :: git apply diff 
Shell :: python print sql in shell_plus 
Shell :: bash while 
Shell :: symbolic link linux 
Shell :: cmd echo without newline 
Shell :: debian change default kernel 
Shell :: awk field separator multiple characters 
Shell :: what is merge conflict in git 
Shell :: chown a file 
Shell :: how to install pipenv 
Shell :: git recover deleted file 
Shell :: git global ingnore 
Shell :: display settings ubuntu 20.04 in right side 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =