awk for scientific notion and decimal combined data


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk for scientific notion and decimal combined data
# 1  
Old 05-05-2011
awk for scientific notion and decimal combined data

Dea all,

I have a question. I have a column of numbers with scientific notion and decimal combined data. I want to print it only if the number <0.05 using awk. however the very small numbers with scientific notion is not selected. Do any one know how to solve it? Thanks! example as below:
data:
Code:
0.04
0.01
0.11
0.55
3.1*e-6

code:
Code:
awk  '($1 <"0.05") {print $1}'

output:
Code:
0.04
0.01

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 05-05-2011 at 12:55 PM.. Reason: code tags, please!
# 2  
Old 05-05-2011
Hi.

Changing the input data, this script works:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate proper scientific & engineering numerical syntax.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for i;do printf "%s" "$i";done; printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C awk

FILE=${1-data1}

pl " Input file $FILE:"
cat $FILE

pl " Results:"
awk '($1 <0.05) {print $1}' $FILE

exit 0

producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.7 (lenny) 
GNU bash 3.2.39
GNU Awk 3.1.5

-----
 Input file data1:
0.04
0.01
0.11
0.55
3.1*e-6
4.1e-6

-----
 Results:
0.04
0.01
4.1e-6

Best wishes ... cheers, drl
# 3  
Old 05-05-2011
Is there a simpler way?

Hi, Thank yuo very much for writing the script. I am wondering if there is a simple way since I new for unix. Is there a way that I could convert the scientific notio0n to decimal? Then I could deal with the data using awk as normal.

Thanks,
Lin
# 4  
Old 05-05-2011
Hi.

If your file has all those asterisks [ * ] in it, I think you can simply remove them. There are a number of ways to do that. You could do it in awk, or use a filter like tr:
Code:
#!/usr/bin/env bash

# @(#) s2	Demonstrate proper scientific & engineering numerical syntax.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for i;do printf "%s" "$i";done; printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C awk

FILE=${1-data1}

pl " Input file $FILE:"
cat $FILE

pl " Results:"
tr -d '*' < $FILE |
awk '($1 <0.05) {print $1}'

exit 0

producing:
Code:
% ./s2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.7 (lenny) 
GNU bash 3.2.39
GNU Awk 3.1.5

-----
 Input file data1:
0.04
0.01
0.11
0.55
3.1*e-6
4.1e-6

-----
 Results:
0.04
0.01
3.1e-6
4.1e-6

See man tr for details ... cheers, drl

( Edit 1: fix minor grammatical typo )

Last edited by drl; 05-07-2011 at 07:40 AM..
# 5  
Old 05-05-2011
awk will do the job as long as your input format is in scientific notation which 3.1*e-6 isnt...so getting rid of asterisk and changing it to 3.1e-6 will work.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Spacing off when files combined using awk or cat

I have 133 .txt files in a directory that I am combining into 1 file. The problem is when I use awk or cat to combine the files I get out put like this: output 85 138662360 KCNT1 86 138662962 KCNT1 82 138657053 KCNT1 83 138657635 KCNT1 95 138646881 KCNT1... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Shell Programming and Scripting

Help with filter result (scientific notation) by using awk

Input file: data1 0.05 data2 1e-14 data1 1e-330 data2 1e-14 data5 2e-60 data5 2e-150 data1 4e-9 Desired output: data2 1e-14 data1 1e-330 data2 1e-14 data5 2e-60 data5 2e-150 I would like to filter out those result that column 2 is less than 1e-10. Command try: (1 Reply)
Discussion started by: cpp_beginner
1 Replies

3. UNIX for Dummies Questions & Answers

How to control the decimal points for p-values in scientific format?

Dear all, I have a txt file with only one column which contains p values. My data looks like this: 5.04726976606584e-190 2.94065711152402e-189 2.94065711152402e-189 9.19932135717279e-176 1.09472516659859e-170 1.24974648916809e-170 0.1223974648916 0.9874974648916 ... what I want... (2 Replies)
Discussion started by: forevertl
2 Replies

4. Shell Programming and Scripting

Combined sed+awk for lookup csv file

have written a combined sed+awk to perform a lookup operation which works but looking to enhance it. looking to match a record using any of the comma separated values + return selected fields from the record - including the field header. so: cat foo make,model,engine,trim,value... (6 Replies)
Discussion started by: jack.bauer
6 Replies

5. Shell Programming and Scripting

awk combined with an IF

Hi everybody! I try to printout a csv-file with the exeption of cell $1 and $4. what i tried so far: awk '{for(i = 1; i<=NF; i++);if(i == 1 || i == 4);else print($i)}' file.csv ..any ideas how it work and why my example fails? Thanks in advance! IMPe (3 Replies)
Discussion started by: IMPe
3 Replies

6. Shell Programming and Scripting

Perl: scientific notation to decimal notation

hello folks, I have few values in a log which are in scientific notation. I am trying to convert into actual decimal format or integer but couldn't able to convert. Values in scientific notation: 1.1662986666666665E-4 2.0946799999999998E-4 3.0741333333333333E-6 5.599999999999999E-7... (2 Replies)
Discussion started by: scriptscript
2 Replies

7. UNIX for Dummies Questions & Answers

Normal format and scientific combined data

hi guys, i have a data with a column of p value (normal format and scientific combined). i want to creat a subset of data which only contains p-value: data 1: p<10^7 data 2: p<0.01 how should i do it? many thanks! data looks like: rs7841347 128887490 1.695e-007 rs1241347 ... (4 Replies)
Discussion started by: forevertl
4 Replies

8. Shell Programming and Scripting

Sorting with header and mixed numerals (scientific and decimal) | awk

Assoc.txt CHR SNP BP A1 TEST NMISS OR STAT P 1 rs2980319 766985 A ADD 4154 1.024 0.1623 0.8711 1 rs2980319 766985 A AGECAT 4154 1.371 6.806 1.003e-11 1 ... (6 Replies)
Discussion started by: genehunter
6 Replies

9. Shell Programming and Scripting

how to convert data from ASCII to Packed Decimal

Hi All, Please let me know if it is possible to convert data from ASCII to Packed Decimal through Unix? Basically we have ASCII file with numeric data we want to convert that files data to Packed decimal format to send it to main frame. Please let me know if we can do it through unix script.... (1 Reply)
Discussion started by: aloktiwary
1 Replies

10. Shell Programming and Scripting

Awk not printing the last combined column

nawk -F "|" 'FNR==NR {a=$2 OFS $3 OFS $4 OFS $5 OFS $6;next}\ {if ($5 in a)print $1,"test",$5,a, $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 ; \ else print $1,"Database",$5 OFS OFS OFS OFS OFS OFS $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 }' OFS="|" \ file1 file2 > file3 This... (5 Replies)
Discussion started by: pinnacle
5 Replies
Login or Register to Ask a Question