<p>It seems a small change. Anyway try ...</p>
<pre><code>perl -p -e 's/(.*NC_[0-9]+\.[0-9]),(NC_[0-9]+\.[0-9].*)/<span class="math-container">$1,\s$</span>2/g' data.txt
</code></pre>
<p>If you have happy that this works, then repeat with an <code>-i</code> flag</p>
<pre><code>perl -p -i -e 's/(.*NC_[0-9]+\.[0-9]),(NC_[0-9]+\.[0-9].*)/<span class="math-container">$1,\s$</span>2/g' data.txt
</code></pre>
<p>I've not checked the code, but it's worth checking whether <code>.*</code> is really needed. Its a while since I've used Perl</p>

CC BY-SA 4.0
2023-02-01T17:03:39.783Z
2023-02-01T17:03:39.783Z
M__
<p>Good afternoon, I'm a bioinformatics student and I'm trying to put some strings between commas with a space. The output looks like this: <code>NC_037078.1:122545-124035,NC_037078.1:96630-98120 </code>and I want it to be like this: <code>NC_037078.1:122545-124035, NC_037078.1:96630-98120 </code></p>
<p>The document is like this:<br />
1. rrn16 <br />
16S ribosomal RNA [Genlisea aurea]<br />
Other Aliases: C7J69_pgr001, BK572_Gau_0120<br />
Genomic context: Chloroplast<br />
Annotation:  NC_037078.1 (122545..124035, complement)<br />
ID:` 36166080</p>
<p>The script until now looks like this:</p>
<pre><code>code=$(ls -l | grep &quot;Annotation&quot; data.txt | cut -d &quot; &quot; -f3,4 | sed 's/[(]/:/g' | sed 's/[)]/ /g' | sed 's/[,]/ /g' | sed 's/[ ]//g' | sed 's/[&quot;.&quot;]/ /g' | sed 's/ /./1' | sed 's/ /-/g' | sed 's/-//1' | tr &quot;\n&quot; &quot;,&quot;)
</code></pre>

CC BY-SA 4.0
2023-02-01T17:04:32.870Z
My first thought is, wow, that's a lot of transformations all piped together. Nothing wrong with that if it works but a little hard to debug. I don't have time just now but I'd recommend trying to figure out either a somewhat more compact one or two sed replacement patterns or a more flexible scripting approach like that suggested by M__.
Maximilian Press
CC BY-SA 4.0
2023-02-01T18:02:57.907Z
The `ls | grep` is pointless, it isn't doing anything useful here.
terdon
CC BY-SA 4.0
2023-02-01T18:13:42.563Z
I can see where you get `NC_037078.1:122545-124035` from your example, but where does `NC_037078.1:96630-98120` come from?
terdon
<shell>
How can I transform this String?
# How can I transform this String?

(Asked by: username_0 on 2023-02-01)

Good afternoon, I'm a bioinformatics student and I'm trying to put some strings between commas with a space. The output looks like this: NC_037078.1:122545-124035,NC_037078.1:96630-98120 and I want it to be like this: NC_037078.1:122545-124035, NC_037078.1:96630-98120 
The document is like this:
1. rrn16 
16S ribosomal RNA [Genlisea aurea]
Other Aliases: C7J69_pgr001, BK572_Gau_0120
Genomic context: Chloroplast
Annotation:  NC_037078.1 (122545..124035, complement)
ID:` 36166080
The script until now looks like this:
code=$(ls -l | grep "Annotation" data.txt | cut -d " " -f3,4 | sed 's/[(]/:/g' | sed 's/[)]/ /g' | sed 's/[,]/ /g' | sed 's/[ ]//g' | sed 's/["."]/ /g' | sed 's/ /./1' | sed 's/ /-/g' | sed 's/-//1' | tr "\n" ",")

**Tags:** shell
> **Comments:**
> **username_1**: My first thought is, wow, that's a lot of transformations all piped together. Nothing wrong with that if it works but a little hard to debug. I don't have time just now but I'd recommend trying to figure out either a somewhat more compact one or two sed replacement patterns or a more flexible scripting approach like that suggested by M__.  
> **username_2**: The `ls | grep` is pointless, it isn't doing anything useful here.  
> **username_2**: I can see where you get `NC_037078.1:122545-124035` from your example, but where does `NC_037078.1:96630-98120` come from?  

---

## 1 answers

### Answer by username_3 on 2023-02-01. Score: 1

It seems a small change. Anyway try ...
perl -p -e 's/(.*NC_[0-9]+\.[0-9]),(NC_[0-9]+\.[0-9].*)/$1,\s$2/g' data.txt

If you have happy that this works, then repeat with an -i flag
perl -p -i -e 's/(.*NC_[0-9]+\.[0-9]),(NC_[0-9]+\.[0-9].*)/$1,\s$2/g' data.txt

I've not checked the code, but it's worth checking whether .* is really needed. Its a while since I've used Perl


---

