I\'m searched for a long time how to do a simple string manipulation in UNIX
I have this string:
theStr=\'...............\'
a="............"
b="${a:0:4}A${a:5}"
echo ${b}
Here is one really good tutorial on string manipulation.
I don't know if it's elegant, or which version of bash you need, but
theStr="${theStr:0:4}A${theStr:5}"
The first part returns first four characters, then the character 'A', and then all the characters starting with the 6th one
You can achieve this with sed
, the stream line editor:
echo $theStr | sed s/./A/5
First you pipe the output of $theStr to sed, which replaces the fifth character with A.