Horje
bash replace beginning of string Code Example
bash replace substring
echo [string] | sed "s/[original]/[target]/g"
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".)
bash replace beginning of string
$ cat shortest.sh
#! /bin/bash

filename="bash.string.txt"

echo ${filename#*.}
echo ${filename%.*}

$ ./shortest.sh
After deletion of shortest match from front: string.txt
After deletion of shortest match from back: bash.string




Shell

Related
linux command to show memory hardware Code Example linux command to show memory hardware Code Example
download sklearn linux Code Example download sklearn linux Code Example
script for restart redis service automatically Code Example script for restart redis service automatically Code Example
kill process by name Code Example kill process by name Code Example
git add and commit all in just one line Code Example git add and commit all in just one line Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11