Extracting rows from a text file if the value of a column falls between a certain range | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Extracting rows from a text file if the value of a column falls between a certain range

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-08-2013
evelibertine evelibertine is offline
Registered User
 
Join Date: May 2011
Last Activity: 22 August 2014, 5:12 AM EDT
Posts: 193
Thanks: 94
Thanked 0 Times in 0 Posts
Extracting rows from a text file if the value of a column falls between a certain range

Hi,

I have a file that looks like the following:


Code:
10      100080417       rs7915867       ILMN_1343295    12      6243093 7747537 
10      100190264       rs2296431       ILMN_1343295    12      6643093 6647537 
10      100719451       SNP94374        ILMN_1343295    12      6688093 7599537 
10      101217090       rs6584276       ILMN_1343295    12      6688093 6947537

I want to extract all the lines where the value in column 2 is within +/- 1,000,000 the range given by the values in columns 6 and 7 (i.e. either between the values in columns 6 and 7, or less than 1,000,000 smaller from the value in column 6, or less than 1,000,000 greater from the value in column 7) Thanks!
Sponsored Links
    #2  
Old 02-08-2013
user8 user8 is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 24 April 2013, 10:34 AM EDT
Posts: 36
Thanks: 0
Thanked 19 Times in 14 Posts
If I understood correctly, you could try this:


Code:
awk '$2>($6-1000000) || $2<($7+1000000)'

While thinking twice, I came to the conclusion that the above should better read


Code:
awk '$2>($6-1000000) && $2<($7+1000000)'


Last edited by user8; 02-09-2013 at 06:46 PM.. Reason: && rather than ||
The Following User Says Thank You to user8 For This Useful Post:
evelibertine (02-08-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting rows from a text file based on the values of two columns (given ranges) evelibertine UNIX for Dummies Questions & Answers 1 10-19-2012 11:36 AM
Extracting rows from a space delimited text file based on the values of a column evelibertine UNIX for Dummies Questions & Answers 2 02-17-2012 01:58 PM
Extracting rows from a text file based on numerical values of a column evelibertine UNIX for Dummies Questions & Answers 1 10-25-2011 01:13 PM
Extracting rows from a text file based on the first column evelibertine UNIX for Dummies Questions & Answers 1 09-19-2011 08:15 PM
Extracting rows from a text file based on the first column evelibertine UNIX for Dummies Questions & Answers 1 08-17-2011 05:53 PM



All times are GMT -4. The time now is 04:32 PM.