Hello
I have a file that contains 10 rows as below:
"ID" "DP"
"ID=GRMZM2G015073_T01" "23.6044288292005"
"ID=GRMZM2G119852_T01" "59.7782287606723"
"ID=GRMZM2G100242_T02" "61.4167813736184"
"ID=GRMZM2G046274_T01" "6.63061838134219"
"ID=GRMZM2G046274_T02" "4.64247483697458"
"ID=GRMZM2G127067_T01" "18.5236594576598"
"ID=GRMZM2G174554_T01" "20.4956070957446"
"ID=GRMZM2G475897_T01" "13.8423337735283"
"ID=GRMZM2G478779_T02" "70.9529571633574"
I want to only display rows in which the 2nd column is above 23 but below 60. I also want the title of the columns namely "ID" and " DP" to be displayed. Obviously both the columns contain strings and not numerical values. I checked these using awk. Any way I want my result to be this:
"ID" "DP"
"ID=GRMZM2G015073_T01" "23.6044288292005"
"ID=GRMZM2G119852_T01" "59.7782287606723"
note: these are the only two rows where second column is above 23 but below 60
I would appreciate any input in any language or single line command.
many thanks
CSN
frans
September 26, 2010, 3:08am
2
this should work
#!/bin/bash
head -1 file
while read L
do
N=${L%.}; N=${N## \"}
((N>=23)) && ((N<60)) && echo $L
done < file
1 Like
kurumi
September 26, 2010, 4:43am
3
$ ruby -ane 'f=$F[1].gsub!("\042","").to_f; print if f > 23 and f < 61;print if $.==1' file
1 Like
awk -F '[".]' 'NR==1 || $4>=23 && $4<60' infile
---------- Post updated at 12:37 ---------- Previous update was at 12:18 ----------
{ read line; echo "$line"
while read line
do
n=${line%.}; n=${n## \"}
if [ $n -ge 23 ] && [ $n -lt 60 ]; then
echo "$line"
fi
done
} < infile
1 Like
Perl one-liner -
$
$
$ cat f23
"ID" "DP"
"ID=GRMZM2G015073_T01" "23.6044288292005"
"ID=GRMZM2G119852_T01" "59.7782287606723"
"ID=GRMZM2G100242_T02" "61.4167813736184"
"ID=GRMZM2G046274_T01" "6.63061838134219"
"ID=GRMZM2G046274_T02" "4.64247483697458"
"ID=GRMZM2G127067_T01" "18.5236594576598"
"ID=GRMZM2G174554_T01" "20.4956070957446"
"ID=GRMZM2G475897_T01" "13.8423337735283"
"ID=GRMZM2G478779_T02" "70.9529571633574"
$
$
$ perl -lane '$F[1]=~s/"//g; print if $.==1 or $F[1]>23 and $F[1]<60' f23
"ID" "DP"
"ID=GRMZM2G015073_T01" "23.6044288292005"
"ID=GRMZM2G119852_T01" "59.7782287606723"
$
$
tyler_durden
1 Like
Thanks every one, I will get back with feedback and more questions soon
csn