Below you will find pages that utilize the taxonomy term “Bash”
November 6, 2012
Replacing in bash without sed
Bash has built-in substitution. For simple tasks it’s easier than piping through sed:
text="hello world"
echo ${text/hello/ohayou} # prints ohayou world
Be aware that just the first word is changed:
text="hello world hello"
echo ${text/hello/ohayou} # prints ohayou world hello
To change all instances of a world, prepend the search pattern with another slash:
text="hello world hello"
echo ${text//hello/ohayou} # prints ohayou world ohayou
Notice there are two slashes before hello, one as the separator and one prepending it.