<p>For any program that prints output to the terminal (standard output), you can always redirect to a file using <code>&gt;</code> or <code>&gt;&gt;</code>. Either of the two will create the output file if it doesn't exist, but <code>&gt;</code> will overwrite any contents of an already existing file, while <code>&gt;&gt;</code> will append to it without overwriting. So you could just do:</p>
<pre><code>seqkit grep -nrp &quot;;s__nosocomialis;&quot; ribogrove_11.217_sequences.fasta &gt; out.fa
</code></pre>

CC BY-SA 4.0
2023-04-23T14:09:42.487Z
2023-04-23T14:09:42.487Z
terdon
<p>Based on <a href="https://bioinf.shenwei.me/seqkit/usage/#grep" rel="noreferrer">the docs</a>, seqkit grep has a <code>-o</code> &quot;output file&quot; option, so if you get the correct output with:</p>
<pre><code>seqkit grep -nrp &quot;;s__nosocomialis;&quot; ribogrove_11.217_sequences.fasta
</code></pre>
<p>Then this command will (in theory) give you your desired outcome:</p>
<pre><code>seqkit grep -nrp &quot;;s__nosocomialis;&quot; ribogrove_11.217_sequences.fasta -o new.fasta
</code></pre>

CC BY-SA 4.0
2023-04-22T06:19:14.277Z
Thanks, it worked. I don't know how i didn't see the output command while surfing the documentation.
Freezing Soul
CC BY-SA 4.0
2023-04-22T06:13:09.460Z
2023-04-22T06:13:09.460Z
jared_mamrot
<p>Consider:</p>
<blockquote>
<p>seqkit grep -nrp &quot;;s__nosocomialis;&quot;  ribogrove_11.217_sequences.fasta</p>
</blockquote>
<p>Using this command lets me select all sequences related to the organism &quot;<em>A. nosocomialis</em>&quot; in the <a href="https://pubmed.ncbi.nlm.nih.gov/35217168/" rel="nofollow noreferrer">RiboGrove</a> database.</p>
<p>How do I save these selected sequences to a new &quot;.fasta&quot; file?</p>

<seqkit>
How do I save selected sequences in seqkit to a file?
# How do I save selected sequences in seqkit to a file?

(Asked by: username_0 on 2023-04-22)

Consider:

> seqkit grep -nrp ";s\_\_nosocomialis;" ribogrove\_11.217\_sequences.fasta

Using this command lets me select all sequences related to the organism "*A. nosocomialis*" in the [RiboGrove](https://pubmed.ncbi.nlm.nih.gov/35217168/) database.

How do I save these selected sequences to a new ".fasta" file?

**Tags:** seqkit

---

## 2 answers

### Answer by username_2 on 2023-04-22. Score: 4 | Accepted answer

Based on the docs, seqkit grep has a -o "output file" option, so if you get the correct output with:
seqkit grep -nrp ";s__nosocomialis;" ribogrove_11.217_sequences.fasta

Then this command will (in theory) give you your desired outcome:
seqkit grep -nrp ";s__nosocomialis;" ribogrove_11.217_sequences.fasta -o new.fasta

> **Comments:**
> **username_0**: Thanks, it worked. I don't know how i didn't see the output command while surfing the documentation.  

---

### Answer by username_1 on 2023-04-23. Score: 1

For any program that prints output to the terminal (standard output), you can always redirect to a file using > or >>. Either of the two will create the output file if it doesn't exist, but > will overwrite any contents of an already existing file, while >> will append to it without overwriting. So you could just do:
seqkit grep -nrp ";s__nosocomialis;" ribogrove_11.217_sequences.fasta > out.fa


---

