Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash script: replace . with :

#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 string

string="stirng" ; echo "${string//ir/ri}"
Comment

bash replace string

#1) Open the file in vi or vim
#2) Run the replacement command in vi (or vim) as follows

# Replace all matching patterns
:s%/PatternToReplace/Replacement

# Replace one matching pattern at a time
:s/PatternToReplace/Replacement
Comment

PREVIOUS NEXT
Code Example
Shell :: install exact version npm 
Shell :: kubernetes service yaml 
Shell :: git stash apply specific stash 
Shell :: where to store ssl certificate on linux 
Shell :: compare strings shell 
Shell :: dos delete 
Shell :: Bash/Shell comment multiple lines 
Shell :: Connecting to WSL2 server via local network 
Shell :: auto run command vim startup 
Shell :: run sh from terminal mac 
Shell :: docker view container logs 
Shell :: undo last commit git 
Shell :: bash open program 
Shell :: restart computer command linux 
Shell :: commit to a new branch 
Shell :: install code ubuntu 
Shell :: Error: ENOSPC: System limit for number of file watchers reached, watch 
Shell :: kill wine process 
Shell :: delete all local images docker 
Shell :: renaming a docker container 
Shell :: bash get user input 
Shell :: install virtualbox ubuntu 
Shell :: awk if else statement 
Shell :: how to uninstall mahjongg in ubuntu 
Shell :: list of git branches 
Shell :: windows download torchvision 
Shell :: bash check if file is empty 
Shell :: install cmake kali 
Shell :: mix ecto.migrate 
Shell :: bluetooth linux protocol not available 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =