bash replace beginning of string
echo [string] | sed "s/[original]/[target]/g"#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".)$ 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
Also in C++:
- uninstall
- ubuntu auto shutdown
- annullare i cambiamenti git
- what all should be added to gitignore for django project
- lsb_release: command not found
- Lock the screen powershell
- rpm install google-chrome-stable in cmd
- linux commands
- brew install pgdump
- open path using terminal ubuntu
- how to reset network on ubuntu 20.04
- command to check size of folder in linux
- reverse shell rubber ducky script
- check memcached status
- Homebrew PHP appears not to be linked. Please run [valet use [email protected]]
- virtualenvwrapper-win
- turn off selinux centos
- how to increase the swap space in linux 7
- yarn install No such file or directory: 'install'
- how to install jupyter notebook using pip
- ubuntu memory command line
- run sh with parameter
- unable to get local issuer certificate git
- making password sensitive/hide in terraform