Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash replace substring

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

replace substring in bash

#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 :: substring frequency 
Shell :: how to restart network manager in kali 
Shell :: Install docker with apt command 
Shell :: jest 
Shell :: sh declare variable 
Shell :: ls all subdirectories 
Shell :: connect to wifi via Terminal 
Shell :: Unit nginx.service is masked 
Shell :: delete git remote heroku 
Shell :: install nomad 
Shell :: bash return last n characters from every line 
Shell :: increment variable bash 
Shell :: live-server command 
Shell :: tar extract to folder 
Shell :: ubuntu zip 
Shell :: git config user settup 
Shell :: gradle threw an error while downloading artifacts from the network. retrying to download 
Shell :: An error occurred while running subprocess capacitor. 
Shell :: How to remove a snap package on Ubuntu 
Shell :: code commit on github 
Shell :: odoo12 installation in ubuntu 16.04 
Shell :: kill port linus 
Shell :: git create branch with specific commit 
Shell :: install safari in ubunut 
Shell :: git change email of old commit 
Shell :: how to find empty folders linux 
Shell :: bash check if python package is installed 
Shell :: linux remove last n lines from file 
Shell :: search git 
Shell :: linux view directory premmisiosns 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =