I'm trying to replace a character in a file at a random position.  My file looks something like:aab  babab  abab  I'm trying to replace a random character for 'c'.  So the output might look like:aab  bcbab  abab I have tried removing all line breaks and saving in a file new_string.txt and then using sed but it isn't working.This is the code I have tried:  rand1=$(shuf -i 0-$tot_len -n 1)sed s/^\(.\{${rand1}\}\)./\1G/ new_string.txtI keep getting the error: sed: -e expression #1, char 25: Invalid content of \{\}
Replacing a character at a random position using sed?
sed
No need for the curly brackets in your variable, and the variable should be quoted as well. Use:sed s/^\(.\{$rand1\}\)./\1G/ new_string.txtUPDATE: as stated below in comments:The original code is fine, however the integer for $rand1 is too large for sed. I found that the maximum value can be 32767 for GNU sed, i.e. sed still takes 16bit integers only.You can obtain that limit for the system's regular expression library (though GNU sed generally uses a builtin version) with:$getconf RE_DUP_MAX32767POSIX requires that limit to be at least _POSIX_RE_DUP_MAX (255), and that's the maximum you can expect portably (some systems like Solaris or OS/X have it as low as that).