Wednesday, November 14, 2012

How to select lines in a file that do not contain specific string/s in Unix

In Unix you can use command grep to cut lines from files that contain specific string/s
http://milospjanic.blogspot.com/2012/11/how-to-use-grep-to-select-specific.html

If you want to use grep to cut the lines that do not contain specific string/s use grep -v

E.g. in file knockdown_without_ra_vs_knockdown_with_ra_genelist.diff I needed to clean the list of genes from the lines containing "-".

Ldhb
St8sia1
5730419I09Rik
Sox5
Bcat1
Itpr2
Tm7sf3
Pthlh
Ipo8
Caprin2
Fam60a
Dennd5b
-
-
-
-
-
-
-
Cntnap2
-
-
-
-
-
-
-
-
D7Ertd143e
Myadm
Prkcc
Cacng7
Cacng8
-
Ndufa3
Prpf31
Cnot3
Tsen34
Rps9
Ttyh1

I used the following command: 
grep -v "-" knockdown_without_ra_vs_knockdown_with_ra_genelist.diff > knockdown_without_ra_vs_knockdown_with_ra_genelist_clean.diff
which removed lines with "-" character and returned only lines with the gene names (that were saved in the new file knockdown_without_ra_vs_knockdown_with_ra_genelist_clean.diff)

No comments:

Post a Comment