Help with text/number parsing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with text/number parsing
# 1  
Old 09-26-2010
Help with text/number parsing

Hello
I have a file that contains 10 rows as below:
Code:
"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:
Code:
"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

Last edited by cs_novice; 09-26-2010 at 03:15 AM.. Reason: typo
# 2  
Old 09-26-2010
this should work
bash code:
  1. #!/bin/bash
  2. head -1 file
  3. while read L
  4. do
  5.    N=${L%.*}; N=${N##*\"}
  6.    ((N>=23)) && ((N<60)) && echo $L
  7. done < file
This User Gave Thanks to frans For This Post:
# 3  
Old 09-26-2010
Code:
$ ruby -ane 'f=$F[1].gsub!("\042","").to_f; print if f > 23 and f < 61;print if $.==1' file

This User Gave Thanks to kurumi For This Post:
# 4  
Old 09-26-2010
Code:
awk -F '[".]' 'NR==1 || $4>=23 && $4<60' infile



---------- Post updated at 12:37 ---------- Previous update was at 12:18 ----------

shell code:
  1. { read line; echo "$line"
  2.   while read line
  3.   do
  4.      n=${line%.*}; n=${n##*\"}
  5.      if [ $n -ge 23 ] && [ $n -lt 60 ]; then
  6.        echo "$line"
  7.      fi
  8.   done
  9. } < infile
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 09-26-2010
Perl one-liner -

Code:
$
$
$ 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
This User Gave Thanks to durden_tyler For This Post:
# 6  
Old 09-27-2010
Thanks every one, I will get back with feedback and more questions soon

csn
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to skip lines find text and add text based on number

I am trying to use awk skip each line with a ## or # and check each line after for STB= and if that value in greater than or = to 0.8, then at the end of line the text "STRAND BIAS" is written in else "GOOD". So in the file of 4 entries attached. awk tried: awk NR > "##"' "#" -F"STB="... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

Text parsing

Hi All! Is it possible to convert text file: to: ? (6 Replies)
Discussion started by: y77
6 Replies

3. Shell Programming and Scripting

Parsing log file and print latest number in loop

Hello All, I have an awk script which parses my log file and prints number grepping from a specific line/pattern, now i have to come with a shell script to continue reading the log untill the job is completed, which i would know while reading session log untill process encounters a final... (1 Reply)
Discussion started by: Ariean
1 Replies

4. Shell Programming and Scripting

Parsing text file

Hi Friends, I am back for the second round today - :D My input text file is this way Home friends friendship meter Tools Mirrors Downloads My Data About Us Help My own results BLAT Search Results ACTIONS QUERY SCORE START END QSIZE IDENTITY CHRO STRAND ... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

5. Shell Programming and Scripting

Parsing text file

I'm totally stumped with how to handle this huge text file I'm trying to deal with. I really need some help! Here is what is looks like: ab1ba67c331a3d731396322fad8dd71a3b627f89359827697645c806091c40b9 0.2 812a3c3684310045f1cb3157bf5eebc4379804e98c82b56f3944564e7bf5dab5 0.6 0.6... (3 Replies)
Discussion started by: comp8765
3 Replies

6. Shell Programming and Scripting

parsing characters and number from a big file with brackets

I have a big file with many brackets () in it from which I need to parse number characters and numbers. Below is an example of my file 14 (((A__0:0.02,B__1:0.3)0:0.04,C__0:0.025)2:0.01),(D__0:0.00978,E__2:0.01031)1:0.00362; 15... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

7. Shell Programming and Scripting

parsing a file name and add a number

Hi, I have a file po8282.fmt998.fbi.mopac.x.macs.btt.txt . I want to parse the first field which is separated by "." and then find the number and add 1 to it. here is what I am doing to get the first field, but not sure how to only pick the number and add 1 to it... (5 Replies)
Discussion started by: rudoraj
5 Replies

8. Shell Programming and Scripting

Parsing text

Hello all, I have some text formatted as follows Name: John doe Company: Address 1: 7 times the headache Address 2: City: my city State/Province: confusion Zip/Postalcode: 12345 and I'm trying to figure out how I could extract the data after the colon so that the result would be ... (6 Replies)
Discussion started by: mcgrailm
6 Replies

9. Shell Programming and Scripting

text parsing querry

$ A=/t1/bin/f410pdb oIFS=$IFS IFS=/ $ set -- $A $ IFS=$oIFS $ echo $2 t1 $ echo $3 bin $ echo $4 f410pdb can any one please explain me what is done with IFS and how it is working internally ...i am interested to know in depth (2 Replies)
Discussion started by: mobydick
2 Replies

10. UNIX for Dummies Questions & Answers

Text parsing question

How would I split a file based on the location of a string, basically I want all entries above the string unix in this example 1 2 3 4 unix 5 6 7 Thanks, Chuck (3 Replies)
Discussion started by: 98_1LE
3 Replies
Login or Register to Ask a Question