want to extract all column which have particular value
2
0
Entering edit mode
3.7 years ago
harry ▴ 40

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 • 888 views
ADD COMMENT
2
Entering edit mode

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.

ADD REPLY
0
Entering edit mode
3.7 years ago
5heikki 11k
awk 'BEGIN{OFS=FS="\t"}{print $0>$7".txt"}' inputFile
ADD COMMENT
0
Entering edit mode
3.7 years ago

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!

ADD COMMENT

Login before adding your answer.

Traffic: 2066 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6