Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

replace all substring in a given string

#To replace the first occurrence of a pattern with a given string,
#use ${parameter/pattern/string}:

#!/bin/bash
firstString="I love Suzi and Marry"
secondString="Sara"
echo "${firstString/Suzi/$secondString}"    

# prints 'I love Sara and Marry'

#To replace all occurrences, use ${parameter//pattern/string}:

message='The secret code is 12345'
echo "${message//[0-9]/X}"           
# prints 'The secret code is XXXXX'


#(This is documented in the Bash Reference Manual, §3.5.3 "Shell Parameter Expansion".)
Comment

PREVIOUS NEXT
Code Example
Shell :: docker active log 
Shell :: adobe connect in ubuntu 
Shell :: install mariadb amazon linux 2 
Shell :: ubuntu grub repair 
Shell :: centos copy files ssh 
Shell :: sh: 1: nodemon: not found 
Shell :: git default remote 
Shell :: start chrome linux 
Shell :: how to run explorer in wsl 
Shell :: how to open chrome on linux mac 
Shell :: patch curl 
Shell :: nvm install ubuntu 
Shell :: how to trim log file linux 
Shell :: redis delete keys that match pattern 
Shell :: apply git diff 
Shell :: make mp4 smaller using ffmpeg 
Shell :: get your ip address from terminal 
Shell :: git bash anaconda 
Shell :: run postgresql command line maccos 
Shell :: error: Not a valid ref: refs/remotes/origin/master 
Shell :: find pip install directory 
Shell :: where is docker images stored windows wsl2 
Shell :: ubuntu sources.list path 
Shell :: react natibe debugger 
Shell :: install docker wsl 
Shell :: reinit git-submodules 
Shell :: delete all files with specific name ubuntu 
Shell :: pacman reinstall 
Shell :: how to unmerge branch in git 
Shell :: How to install LAMP in Ubuntu 20.04? 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =