Hello everyone,

My file had 12 columns, I want those lines in my file where numbers in columns 9 and 10 includes digit "101".

For example : i am giving 3 lines of my file: ( columns to focus are colored green).

NM013123 14-74726235 100.00 18 0 0 11 28 141 100 0.080 36.2
NM013123 14-74726339 100.00 18 0 0 11 28 38 21 0.080 36.2
NM013123 14-74726235 100.00 18 0 0 11 28 80 124 0.080 36.2

Result file should have lines:
NM013123 14-74726235 100.00 18 0 0 11 28 141 100 0.080 36.2
NM013123 14-74726235 100.00 18 0 0 11 28 80 124 0.080 36.2

because "101" lies between 141 and 100
& between 80 and 124.

please help me...

Many Thanks in advance..

Here's what I would do:

-First, get a linelist of your input file. (ex yourfile.read().split('\n'))
-Then, create a output linelist (ex output_list = [])
-Fill it up! (see below)

for line in linelist:
    column_list = line.split('\t') #splits the line into columns
    compare_list = [int(column_list[8]),int(column_list[9])]
    compare_list.sort() #the smallest value is now first
    if 101 in range(compare_list[0],compare_list[1]):
        output_list.append(line) #101 is between those two numbers, save the line!

Then, write your output list to your new file.

You could also turn the above code into a function to return the line if 101 is between the values, or false if not, make a class that does everthing, etc etc but the functionality should be as simple as that.

EDIT: I just tested this, line.split(' ') doesn't return the column_list. My bad. It's actually line.split('\t') which says split on the tab. Code has been updated. Hope this works for you!

Hi,

Thanks for replying...
my problem is solved..


Thanks again

This question has already been answered. Start a new discussion instead.