<p>Invest some time in learning unix tools such as <code>grep</code>, <code>sed</code> and <code>awk</code>.</p>

<pre><code>sed -r '/^&gt;/s/:[0-9]+-[0-9]+//' input.fasta &gt; output.fasta
</code></pre>

<p>This line of code matches the pattern <code>:&lt;numbers&gt;-&lt;numbers&gt;</code> on lines that start with <code>&gt;</code> (FASTA sequence headers) and replaces that pattern with <code>''</code>, essentially removing text that matches the pattern.</p>

CC BY-SA 4.0
2019-07-03T22:26:57.487Z
Thanks Ram, could you please suggest any book related to unix command line that can explain all these small problems related to bioinformatics.
bioinfonext
CC BY-SA 4.0
2019-07-03T23:01:43.720Z
I'd recommend looking at [Rosalind](http://rosalind.info/problems/locations/), but I think that's mostly python. Unix utilities are learnt as you stumble upon problems, as there's seldom some sort of comprehensive exercise to learn these utilities. Try googling "learn sed" or "learn grep" or "learn awk" and following tutorials that pop up. For awk, you can start with an Excel sheet of data, export the data to a tab-separated text file and use `awk` to do things you'd normally use Excel filters to do.
Ram RS
CC BY-SA 4.0
2019-07-03T22:13:37.497Z
2019-07-04T08:57:55.713Z
2019-07-04T08:57:55.713Z
Ram RS
<p>Alternatively, Perl provides a slightly simpler regular expression syntax (<code>\d</code> instead of <code>[0-9]</code>) that I prefer over <code>sed</code>.</p>

<pre><code>perl -pe 's/:\d+-\d+//' input.fasta &gt; output.fasta
</code></pre>

CC BY-SA 4.0
2019-07-09T23:20:52.930Z
Using `-pe` is even simpler: `perl -pe 's/^(>\S+):\d+-\d+/$1/' input.fasta > output.fasta`
user172818
CC BY-SA 4.0
2019-07-09T20:47:21.120Z
2019-07-10T13:03:00.690Z
2019-07-10T13:03:00.690Z
Daniel Standage
<p>Could you please suggest me how I can remove range from fasta header:like these number from below sequences which has some colons indicating the range of the genome</p>

<p>:147010-147657 </p>

<p>:149201-149845</p>

<pre><code>&gt; FVJT01000004.1:147010-147657 Mycobacterium abscessus subsp. massiliense strain 974 
GTGACCAGCAGCGCAGACCGATCCCCCGTCGAGGCGATGGTGAGCCACGCCGAGGGCGCCATCTCCGAGG
ATGACATCGTCGCCGCCGCCCGGGAACGTGCCGTTGACCTGGGCGCGGGCCCGGTGACACCCGCGGTAGG

&gt;FSAX01000002.1:149201-149845 Mycobacterium abscessus subsp. bolletii strain 286 genome 
ATGACGACGCCCGTCAGCTTCGATAACAGATTCTTCTCCGCAACGTGGTCTGCTATCGCGCGGCGCGAAC
CTCAGGAGATCAAGGAGCTGCGTGCGGAGAATCTACGCGGCCTGACCGGCCACGTTCTGGAGGTGGGAGC
</code></pre>

<bash>
how to remove range from fasta header
# how to remove range from fasta header

(Asked by: username_0 on 2019-07-03)

Could you please suggest me how I can remove range from fasta header:like these number from below sequences which has some colons indicating the range of the genome
:147010-147657 
:149201-149845
> FVJT01000004.1:147010-147657 Mycobacterium abscessus subsp. massiliense strain 974 
GTGACCAGCAGCGCAGACCGATCCCCCGTCGAGGCGATGGTGAGCCACGCCGAGGGCGCCATCTCCGAGG
ATGACATCGTCGCCGCCGCCCGGGAACGTGCCGTTGACCTGGGCGCGGGCCCGGTGACACCCGCGGTAGG

>FSAX01000002.1:149201-149845 Mycobacterium abscessus subsp. bolletii strain 286 genome 
ATGACGACGCCCGTCAGCTTCGATAACAGATTCTTCTCCGCAACGTGGTCTGCTATCGCGCGGCGCGAAC
CTCAGGAGATCAAGGAGCTGCGTGCGGAGAATCTACGCGGCCTGACCGGCCACGTTCTGGAGGTGGGAGC

**Tags:** bash

---

## 2 answers

### Answer by username_1 on 2019-07-03. Score: 6 | Accepted answer

Invest some time in learning unix tools such as grep, sed and awk.
sed -r '/^>/s/:[0-9]+-[0-9]+//' input.fasta > output.fasta

This line of code matches the pattern :- on lines that start with > (FASTA sequence headers) and replaces that pattern with '', essentially removing text that matches the pattern.

> **Comments:**
> **username_0**: Thanks Ram, could you please suggest any book related to unix command line that can explain all these small problems related to bioinformatics.  
> **username_1**: I'd recommend looking at [Rosalind](http://rosalind.info/problems/locations/), but I think that's mostly python. Unix utilities are learnt as you stumble upon problems, as there's seldom some sort of comprehensive exercise to learn these utilities. Try googling "learn sed" or "learn grep" or "learn awk" and following tutorials that pop up. For awk, you can start with an Excel sheet of data, export the data to a tab-separated text file and use `awk` to do things you'd normally use Excel filters to do.  

---

### Answer by username_2 on 2019-07-09. Score: 1

Alternatively, Perl provides a slightly simpler regular expression syntax (\d instead of [0-9]) that I prefer over sed.
perl -pe 's/:\d+-\d+//' input.fasta > output.fasta

> **Comments:**
> **username_3**: Using `-pe` is even simpler: `perl -pe 's/^(>\S+):\d+-\d+/$1/' input.fasta > output.fasta`  

---

