Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

substring replacement

#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 :: string manipulation in shell 
Shell :: install exact version npm 
Shell :: clean my ubuntu 
Shell :: remove all iptables rules 
Shell :: bash or 
Shell :: search in centos terminal 
Shell :: restart nginx mac 
Shell :: ubuntu cmd firewall give access to port 
Shell :: install java 16 ubuntu 
Shell :: az login acr -n 
Shell :: how to install ssh in windows 10 
Shell :: how to check whether git is initialized or not 
Shell :: git how to make shallow clone with all branches 
Shell :: get ORACLE_HOME linux 
Shell :: open chrome without web security mac 
Shell :: github repo with most issues 
Shell :: remove last space from line 
Shell :: install node js redhat 8 
Shell :: gzip folder .gz file in linux 
Shell :: bash add new line to crontab 
Shell :: ubuntu install mathpix 
Shell :: install memcache di linux 
Shell :: install plasma arch 
Shell :: apply gitignore after commit 
Shell :: untar gz file ubuntu 
Shell :: set gunicorn timeout via command 
Shell :: close chrome tab from command line ubuntu 
Shell :: powershell add to env path 
Shell :: git always commit with gpg 
Shell :: kali linux change keyboard layout 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =