# separate genes with expression values

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.

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.

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.