0

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 2

3
echo set18set18_nopep.fa | sed 's|[0-9]\+|&/|'

Output:

set18/set18_nopep.fa
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.