Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash replace substring

echo [string] | sed "s/[original]/[target]/g"
Comment

replace substring in shell

#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

bash replace substring in string

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

PREVIOUS NEXT
Code Example
Shell :: replace all substring in a given string 
Shell :: git go back to previous commit remote branch 
Shell :: install plasma on ubuntu 
Shell :: deactivate laptop keyboard ubuntu 
Shell :: linux list top cpu processes 
Shell :: intall mondg brew 
Shell :: postgres install mac 
Shell :: verify xcode command tools installation 
Shell :: how to get all file names in a folder in shell script 
Shell :: install pcl ubuntu 
Shell :: enable proxy in cmd 
Shell :: access wine directory mac os 
Shell :: install python module ImageTk 
Shell :: echo export path 
Shell :: how to customize grub 
Shell :: adb push image to gallery 
Shell :: remove space at end of each line file 
Shell :: start ssh macos 
Shell :: cannot find module json-loader 
Shell :: stop supervisor service centos 8 
Shell :: git move changes to new branch 
Shell :: error: The following untracked working tree files would be overwritten by merge: static/platform_images/landing_page_img.png Please move or remove them before you merge. Aborting 
Shell :: how to restart raspberrypi via ssh 
Shell :: how to get remote origin url 
Shell :: solving environment failed with initial frozen solve 
Shell :: ubuntu install jellyfin 
Shell :: cd /usr/local/bin/composer 
Shell :: how to install free download manager on linux 
Shell :: pesquisar codigo commit 
Shell :: aws connect to eks cluster 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =