<p>What do you want to do with NA values?</p>

<p>The below scripts ignore them (h3ab74's answer will print them to positiveExpression)</p>

<pre><code>awk '<span class="math-container">$2 ~ /^[0-9]+$</span>/  {print <span class="math-container">$0}' expressionFile.txt &gt; positiveExpression.txt
awk '$</span>2 ~ /^-[0-9]+<span class="math-container">$/ {print $</span>0}' expressionFile.txt &gt; negativeExpression.txt
</code></pre>

<p>These do a regex match to respectively, positive and negative numbers. If there's anything else in field 2 the line won't be printed. </p>

CC BY-SA 4.0
2020-06-01T12:21:53.193Z
2020-06-01T12:21:53.193Z
Greg
<pre><code>awk '{if(<span class="math-container">$2&gt;0) print $</span>0}' expressionFile.txt &gt;&gt; positiveExpression.txt
awk '{if(<span class="math-container">$2&lt;0) print $</span>0}' expressionFile.txt &gt;&gt; negativeExpression.txt
</code></pre>

<p>Assuming that the file with gene expressions has the title: expressionFile.txt, this should do the trick.</p>

<p>Explanation of first line of code: if values in the 2nd column - <code>$2</code> - are greater than 0, print all columns (<code>$0</code>) and write to a file (<code>&gt;&gt;</code>) titled, positiveExpression.txt. The use of <code>awk '{}'</code> is just syntactical. </p>

CC BY-SA 4.0
2020-05-30T14:56:29.860Z
2020-05-30T15:01:45.293Z
2020-05-30T15:01:45.293Z
h3ab74
<p>I have a file like this with 2 columns. I want to separate the columns based on plus and minus signs into separate files. How do I do this with awk or sed. Kindly help.    </p>

<p><a href="https://i.sstatic.net/my8CN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/my8CN.png" alt="enter image description here"></a></p>

<text-processing><awk>
separate genes with expression values
# separate genes with expression values

(Asked by: username_0 on 2020-05-30)

I have a file like this with 2 columns. I want to separate the columns based on plus and minus signs into separate files. How do I do this with awk or sed. Kindly help.

[![enter image description here](https://i.sstatic.net/my8CN.png)](https://i.sstatic.net/my8CN.png)

**Tags:** text-processing, awk

---

## 2 answers

### Answer by username_1 on 2020-06-01. Score: 3 | Accepted answer

What do you want to do with NA values?
The below scripts ignore them (h3ab74's answer will print them to positiveExpression)
awk '$2 ~ /^[0-9]+$/  {print $0}' expressionFile.txt > positiveExpression.txt
awk '$2 ~ /^-[0-9]+$/ {print $0}' expressionFile.txt > negativeExpression.txt

These do a regex match to respectively, positive and negative numbers. If there's anything else in field 2 the line won't be printed.


---

### Answer by username_2 on 2020-05-30. Score: 1

awk '{if($2>0) print $0}' expressionFile.txt >> positiveExpression.txt
awk '{if($2<0) print $0}' expressionFile.txt >> negativeExpression.txt

Assuming that the file with gene expressions has the title: expressionFile.txt, this should do the trick.
Explanation of first line of code: if values in the 2nd column - $2 - are greater than 0, print all columns ($0) and write to a file (>>) titled, positiveExpression.txt. The use of awk '{}' is just syntactical.


---

