Hi I have wrapped a sed command (which works out it's own) within a shell function.
#!/bin/bash
snp2fasta() {
sed -i "s/^\(.\{'$2'\}\)./\1'$3'/" $1;
}
and call it with
$ ./snp2fasta input.txt 45 A
no changes are made to input.txt
However if I simply do
$ sed -i 's/^\(.\{45\}\)./\1A/' input.txt
then this works and the file is changed by changing the 45th character to an A.
However when wrapping into a shell script (to handle command line variables) the shell script snp2fasta.sh runs fine, but no changes are made to the file.
why is this?
set -xjust before the sed call to see what it actually runs."".likesed -i 's/^\(.\{"$2"\}\)./\1"$3"/' "$1";