Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-23T14:09:42.487Z
Answers.LastActivityDate: 2023-04-23T14:09:42.487Z
Answers.UserDisplayName: terdon
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-22T06:19:14.277Z
Answers.Text: Thanks, it worked. I don't know how i didn't see the output command while surfing the documentation.
Answers.UserDisplayName: Freezing Soul
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-22T06:13:09.460Z
Answers.LastActivityDate: 2023-04-22T06:13:09.460Z
Answers.UserDisplayName: jared_mamrot
Body: <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>
  
Tags: <seqkit>
Title: How do I save selected sequences in seqkit to a file?
ThreadText: # 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](https://bioinf.shenwei.me/seqkit/usage/#grep), 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
  
  ```
  
  
  ---
  
  