This is a test version of Biostars. For the public version, visit https://www.biostars.org.
want to extract all column which have particular value

I want to separate the column on the basis of $7=-1 or $7=1 value. So is there awk command to doing this?

10      100009838       100009947       ENST00000324109 ENSE00001424407 1       -1
    10      100042193       100042573       ENST00000370418 ENSE00001887192 9       -1
    10      100048758       100048876       ENST00000370418 ENSE00003381123 8       -1
    10      100048767       100048876       ENST00000441382 ENSE00001655587 5       -1
    10      100054347       100054446       ENST00000370418 ENSE00000811303 7       -1
    10      100054347       100054446       ENST00000441382 ENSE00000811303 4       -1
    10      100057013       100057152       ENST00000370418 ENSE00000811302 6       -1
    10      100057013       100057152       ENST00000441382 ENSE00000811302 3       -1
    10      100063614       100063725       ENST00000370418 ENSE00000811301 5       -1
    10      100063614       100063725       ENST00000441382 ENSE00000811301 2       -1
    10      100065188       100065370       ENST00000370418 ENSE00000811300 4       -1
    10      100065188       100065394       ENST00000441382 ENSE00001605944 1       -1
    10      1000677 1000868 ENST00000360803 ENSE00003613229 7       1
    10      1000677 1000868 ENST00000491635 ENSE00003567401 5       1
    10      100069714       100069869       ENST00000370418 ENSE00003404628 3       -1
    10      100075911       100076107       ENST00000370418 ENSE00003305953 2       -1
    10      100081403       100081869       ENST00000370418 ENSE00001452668 1       -1

Thanks in advance

extract awk

Please clarify if you want to separate all rows that have either 1 or -1 into two separate files.

want to extract all column which have particular value

You are asking about column 7 but have not clarified what you want to do with the rest of the columns.

2 answers

awk 'BEGIN{OFS=FS="\t"}{print $0>$7".txt"}' inputFile

I know this question has been answered prior, but you could also solve this issue using a small Python script, as detailed below:

file = open(file_name)
final_list = []
for item in file:
     line = item.split()
     if(line[6] == "1" or line[6] == "-1"):
          final_list.append(item)
file.close()

Hope this helped!

Log in to answer this question.