I am stuck at replacing a set of strings using bash. The strings looks like set18set18_nopep.fa. I want to replace the string with set18/set18_nopep.fa .The number can go from 1-9999 . So the number of digits is also variable.
2 Answers
To put a slash between the end of the numbers and the word set:
$ s=set18set18_nopep.fa
$ echo "$s" | sed -r 's|([[:digit:]])set|\1/set|'
set18/set18_nopep.fa
To assign the new value to a string called t:
$ t=$(echo "$s" | sed -r 's|([[:digit:]])set|\1/set|')
$ echo "$t"
set18/set18_nopep.fa