View Single Post
Old 2016-02-28, 02:45   #4
Batalov's Avatar
Mar 2008

216458 Posts

Originally Posted by unconnected View Post
I use this construction for cut ranges from the .npg files:
awk '{if (($2>4000000) && ($2<4100000)) print $0}' 5.npg
awk is a good tool to use for many operations with npg files.
Especially when you are dealing with wide ranges of values (over one power of magnitude; grep patterns are still possible but ugly).
Yet another way for capturing a range like this is 'int($2/100000)==40'

All of these are equivalent (note that is you are only print'ing then awk 'condition' is equivalent to awk '{if(condition){print}}' ):
awk '{if (($2>=4000000) && ($2<4100000)) print $0}' 5.npg
awk '$2>=4000000 && $2<4100000' 5.npg
awk 'int($2/100000)==40' 5.npg

# Unrelated; here is a simple trick to find squares in the first column
awk 'int(sqrt($1+0.1))**2==$1' 5.npg
# here +0.1 is to avoid rare sqrt return values like 719.9999, costs nothing
Batalov is offline   Reply With Quote