Visit The New, Modern Unix Linux Community

Finding absolute values greater than a certain value

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding absolute values greater than a certain value
# 1  
Finding absolute values greater than a certain value

Hi I am posting here for the first time. I am trying to write a script that reads a data file and tries to determine if any absolute values that are above 0.5

I was thinking it ought to be possible to do this with awk somehow. Are there any suggestions before I start reinventing the wheel?

Here is an example of the data from the file.

0.0000000 0.4984217 0.3092685 -0.1302824 -0.3685155
# 2  
awk ' function abs(val) {return (val < 0 ) ? val *-1: val }
      { if (abs($3) >= .5) { print $0}; next } ' inputfile

You can add code for $1 $2 etc for each field in your file.
# 3  
cat urfile |xargs -n1 |awk '$1>0.5'


awk '{for (i=1;i<=NF;i++) {if ($i>0.5) {print $i}}}' urfile

# 4  
The OP wants the equivalent of the abs() function
# 5  
Thanks Jim, I update the code with your awk abs function.

$ awk 'function abs(val) {return val>0?val:-val }
{for (i=1;i<=NF;i++) {if (abs($i)>0.3) {print $i}}}' urfile

I change the 0.5 to 0.3 to confirm the script is correct, otherwise no output.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #916
Difficulty: Easy
In Javascript, the console is an object which provides access to the browser debugging console.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace the field values, which are greater than the specified value with TRUE?

I have a csv file as given below, org1 org2 org3 org4 org5 gene1 100 80 90 80 150 gene2 30 70 50 50 115 gene3 40 120 60 40 105 gene4 20 72 40 60 20 I need to replace the fields are having values greater than 100 with "TRUE". I used the following commands to replace... (6 Replies)
Discussion started by: dineshkumarsrk
6 Replies

2. Shell Programming and Scripting

How to print values that are greater than 0.1 in at least 80% of the samples?

input sample1 sample2 sample3 sample4 sample5 sample6 sample7 sample8 sample9 sample10 v1 0.2 0.1 0.1 0 1 2 3 4 9 10 v2 0 0 0.01 0 0 0 0 0 0 0 v3 0 0 0 0 0 ... (35 Replies)
Discussion started by: quincyjones
35 Replies

3. Shell Programming and Scripting

Help me to find a greater than or smaller than values

Hi, i need to find one of the value from my file is in between two numbers, that is the value is greater than 34 and smaller than 50, Ex: File.txt col1 col2 col3 col4 1 Name1 93 w 2 Name2 94 a 3 Name3 32 b 4 Name4 45 x 5 Name5 50 y 6 Name6 49 z here i need to find col3 values are... (7 Replies)
Discussion started by: Shenbaga.d
7 Replies

4. Shell Programming and Scripting

awk to get values greater than

data.txt August 09 17:16 2013 August 09 17:17 2013 August 09 17:19 2013 August 09 17:20 2013 August 09 17:21 2013 August 09 17:22 2013 August 09 17:23 2013 August 09 17:24 2013 to print from a point in this file, to the end of the file, i type: awk '/August 09 17:22/,0' data.txt. ... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Shell Programming and Scripting

Choosing between repeated entries based on the "absolute values" of a column

Hello, I was looking for a way to select between the repeated entries (column1) based on the values of absolute values of column 3 (larger value). For example if the same gene id has FC value -2 and 1, I should get the output as -2. Kindly help. GeneID Description FC ... (2 Replies)
Discussion started by: Sanchari
2 Replies

6. UNIX for Advanced & Expert Users

Finding causes of slabinfo values

I'm doing a little work on assessing and improving server stability. As part of that, we're reviewing the contents of /proc/slabinfo. We see that sometimes a certain metric-- say, buffer_head-- spike prior to server instability. We're interested in learning what contributes to that as we trace... (0 Replies)
Discussion started by: treesloth
0 Replies

7. Shell Programming and Scripting

finding values in between

Hi, I have been trying to find someone with this similar problem but I was out of luck. So I have a file that has two columns that look like this (for example): 10 20 40 50 45 60 90 130 So column 1 is start and column 2 is stop but what I want to do is find whats not represented... (4 Replies)
Discussion started by: phil_heath
4 Replies

8. Shell Programming and Scripting

Important finding --- find files greater than 1 MB

as we can find file greater than 1 MB with find command as: find /dir -name '*' -size +1M find /dir/* -name '*' -size +1M but wats its doing is , its finding files only in current directory not in sub-directories. i want files from sub-directories too. Please help... Thanx in... (3 Replies)
Discussion started by: manoj_dahiya22
3 Replies

9. Shell Programming and Scripting

Finding files with names that have a real number greater then difined.

I am trying to find all files in a directory whose name has a real number larger then the number I am looking for. For example: . |-- delta.1.5.sql |-- delta.2.1.sql |-- delta.2.2.sql |-- delta.2.3.sql |-- delta.2.4.sql `-- delta.2.5.sql I know my database is at 2.2 so I want an... (2 Replies)
Discussion started by: harmonwood
2 Replies

10. UNIX for Dummies Questions & Answers

Finding absolute pathnames longer than 100 characters

Please help. This simple problem is really stumping me. Is there are way to find absolute pathnames for all files on your system that are longer than 100 characters? I'm using bash shell to attempt it, but have come up with nothing so far. I appreciate any help offered. Nauty (2 Replies)
Discussion started by: nauty
2 Replies

Featured Tech Videos