Sponsored Content
Top Forums UNIX for Dummies Questions & Answers awk for scientific notion and decimal combined data Post 302519947 by drl on Thursday 5th of May 2011 12:27:35 PM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
binary2ascii(1) 					      General Commands Manual						   binary2ascii(1)

NAME
binary2ascii - Convert binary numbers to textual representation SYNOPSIS
binary2ascii [flags] DESCRIPTION
binary2ascii reads input consisting of binary numbers and converts them to their textual representation. Command line flags specify the type and size of the binary numbers and provide control over the format of the output. Unsigned integers may be written out in binary, octal, decimal, or hexadecimal. Signed integers may be written out only in binary or decimal. Floating point numbers may be written out only in decimal, either in standard or scientific notation. (If you want to examine the binary representation of floating point numbers, just treat the input as a sequence of unsigned characters.) COMMAND LINE FLAGS
Long options may not be available on some systems. -b,--base <base> Base for integer conversions: b(binary),d(ecimal), h(exadecimal), o(ctal), or 2,8,10, or 16. -d,--delimit Delimit the output as per the locale. This is the default on systems in which printf(3) supports delimitation. If delimitation is not enabled, floating point numbers will have a decimal point and no separation of groups, integers no delimiters at all. With this option, the decimal separator will be chosen according to the locale (which, for example, may make it a comma), and non-fractional digits will be grouped and separated according to the rules for the locale in force. For American English, this means groups of three digits separated by commas, whereas for German in Germany it means groups of three digits separated by periods. -D,--do-not-delimit Do not delimit the output as per the -d option. -e,--exponential Use exponential (scientific) notation. -h,--help print help message -l,--linefeed add a linefeed after every 0x0A value if the size is char, short, int, or long, that is, the sizes that might represent a character. -L,locale <locale> Set the LC_NUMERIC facet of the locale to <locale>. -n,--number <number> number of items to print per line. -o,--offset <offset> byte offset at which to start. -p,--precision <precision> the precision to use when printing floating point numbers. -s,--sizes print sizes of types on current machine and related information -t,--type <type> set type and size of input -x,--no-hex-mark do not mark hexadecimal output with the prefix 0x. -V,--verbose be verbose. -v,--version print version information. -w,--width minimum field width. -X,--explain-exit-codes print a summary of the exit status codes. -z,--zero-pad-integers zero pad on left. -Z,--do-not-zero-pad-integers do not zero pad on left INPUT TYPES
The following are the possible input types. Note that some types may not be available on some machines. d double f float q long double sc signed char ss signed short si signed int sl signed long sq signed long long uc unsigned char us unsigned short ui unsigned int ul unsigned long uq unsigned long long EXIT STATUS
The following values are returned on exit: 0 SUCCESS The input was successfully converted. 1 INFO The user requested information such as the version number or usage synopsis and this has been provided. 2 SYSTEM ERROR An error resulted from a failure of the operating system such as an i/o error or inability to allocate storage. 3 COMMAND LINE ERROR The program was called with invalid or inconsistent command line flags. 5 INPUT ERROR This means that the input was ill-formed, that is that it could not be interpreted as a number of the required type. For example, if the input is 0x2A and a decimal value is called for, an INPUT ERROR will be returned since 0x2A is not a valid representation of a decimal integer. AUTHOR
Bill Poser (billposer@alum.mit.edu) LICENSE
GNU General Public License, version 3 SEE ALSO
ascii2binary(1) July, 2010 binary2ascii(1)
All times are GMT -4. The time now is 03:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy