Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [numeric-data]

The tag has no usage guidance.

3
votes
4answers
154 views

How to grep and cut numbers from a file and sum them

I have a log file. For every line with a specific number, I want to sum the last number of those lines. To grep and cut is no problem but I don't know how to sum the numbers. I tried some solutions ...
0
votes
2answers
43 views

Add two doubles on bash

I'm trying to add two doubles y1=0.17580197E-01 y2=0.11979236E-02 sum=`echo $y1+$y2 | bc -l` the above script gives me sum = -2.704405652. How do i resolve this issue?
1
vote
0answers
23 views

bc command unexpected results [duplicate]

I am trying to compare a decimal and it seems like bc is ignoring it. The OS is CentOS release 6.9 (Final) and bash is bash-4.1.2-48.el6.x86_64, below is the code #!/bin/sh i=32.39 IP_LOW_2=32.0 ...
-1
votes
3answers
71 views

What does the following number-processing sed code mean?

I came across a code in script which add ',' after every 3 digits from backwards. the code only considers numeric data. Following is the code. sed 's/\(^\|[^0-9.]\)\([0-9]\+\)\([0-9]\{3\}\)/\1\2,\3/...
3
votes
2answers
173 views

How to obtain only positive value in second column [closed]

I use this command awk 'NR%2{t=$1;next}{print $1-t,$2}' to get the distance between two consecutive Y points in a file. But I would like to have all positive numbers. How to get that ? like ...
-1
votes
1answer
19 views

find in a file where sign of a column entry changes and print first line where this happens

I have multiply files, each with three columns. I would like to monitor where a given column entries first change sign (i.e negative to positive) so that I save that row where this first happens to ...
1
vote
2answers
38 views

How to sort comma-thousand separated numbers while on other locale

I have a German locale and need to sort US formatted numbers with commas as the thousands separator. Seems I don't override the locale properly? sort --version sort (GNU coreutils) 8.30 Example: ...
6
votes
2answers
255 views

How to read string as hex number in bash?

I have the bash line: expr substr $SUPERBLOCK 64 8 Which is return to me string line: 00080000 I know that this is, actually, a 0x00080000 in little-endian. Is there a way to create integer-...
2
votes
2answers
93 views

String to integer in Shell

I'm currently working on a project called 'dmCLI' which means 'download manager command line interface'. I'm using curl to multi-part download a file. And I'm having trouble with my code. I can't ...
2
votes
1answer
29 views

How to reflect data points across their median line?

Sample Input file name 0.00 -1.0000 number1 0.00 -0.8000 number2 0.00 -0.6000 number3 0.00 -0.4000 number4 0.00 -0.2000 number5 0.00 0.0000 number6 0.00 0.2000 number7 0....
0
votes
2answers
55 views

When I add 0 to 0.0, how do I make sure the result is 0.0 not 0?

There are two columns of numbers in a file, the first line like this: 0 0.0 I want to add the numbers in column 1 to those in column 2, and I want to keep the results floats, not ...
1
vote
2answers
46 views

Search specific numbers

im a list numbers in file and i would search 1 specific number in string Es. 1 54 67 78 32 11 4 67 89 90 13 67 87 32 21 My search is 1 With awk or grep commands out this numbers 1 11 13 ...
0
votes
2answers
35 views

If I have a number in a shell script, how would i access just one digit of that number? [closed]

I want to be able to go through and access each digit individually in a shell script. How would I do this?
5
votes
1answer
86 views

Why does gawk treat `0123` as a decimal number when coming from the input data?

According to $ man gawk, the strtonum() function can convert a string into a number: strtonum(str) Examine str, and return its numeric value. If str begins ...
0
votes
4answers
66 views

Find the largest positive number in my given data?

Can someone show me a way to find the largest positive number using awk,sed or some sort of unix shell program? I'm using Linux RHEL with KSH. The input may have 8 columns worth of data with N/A as ...
2
votes
6answers
379 views

count how many times each number occurs

A file contains 5 columns with numbers Example: 12 34 67 88 10 4 90 12 10 7 33 12 5 76 34 I would like to print the same number and see how many times it goes out. Example: 3 : 12 2 : 34
5
votes
6answers
1k views

How do I add numbers from two txt files with Bash?

I have a txt file that contains some numbers like this: 1 2 3 4 5 And I have another txt file that contains the same number of lines, but with other numbers: 6 7 8 9 10 I want ...
1
vote
0answers
31 views

Compute median over windows and groups

I have a file that looks like this: chr pos value A 1 23 A 2 32 ... A 200 32 ... B 1 41 B 2 28 ... The file is sorted by chr and pos. The ... is just to show the lots of rows in ...
3
votes
2answers
39 views

Creating numerous ranges or blocks of folders/directories?

[EDITED to reflect answers below] I am looking for a way to create blocks of folders / directories from the command line or a script that will generate a top level folder titled "200000-209999" and ...
0
votes
0answers
57 views

Find consecutive integers from list of numbers

With a file of integers separated by newlines, I would like to search for consecutive integers, then list the amount of integers that are consecutive per uninterrupted sequence, as well as the ...
4
votes
4answers
250 views

Make awk produce error on non-numeric

I have a program that sums a column in a file: awk -v col=2 '{sum+=$col}END{print sum}' input-file However, it has a problem: If you give it a file that doesn't have numeric data, (or if one number ...
0
votes
1answer
50 views

Calculate difference in negative floating numbers with bc

I want to calculate the difference between two negative floating numbers and subsequently check if the result is below a certain threshold. The numbers are stored in the file.dat, since this ...
3
votes
2answers
76 views

A Unix AIX variable without a $ symbol?

I'm trying to debug an existing program and found an if condition without $ symbol prefixed to it. Values are: dt_val=1234 prev_dt_val=1234 If condition goes like: if [ dt_val -eq prev_dt_val ] ...
0
votes
3answers
93 views

Find the min and max value of column 3 and print whole row

I have huuuge sets of data consisting of 3 columns. I'd like to be able to find max and min values in the third column (there is mix of zeros and then negative values, so I want to find max negative ...
2
votes
1answer
44 views

Awk - convert time value to decimal value

How can I use awk to convert a time value to a decimal value. I have been using this command for the other way round (-> from): awk '{printf "%d:%02d", ($1 * 60 / 60), ($1 * 60 % 60)}' <<< ...
0
votes
2answers
453 views

Grep only numbers, not the alphanumeric entries

I have a list of values like: 1 2 3 4 Ak123 Ak23 Ak147 1Apple 2Apricot 3Mango 4Orange I just want to execute a simple grep command to list me only the numbers. i.e. 1, 2 , 3 and 4. I tried this ...
4
votes
3answers
387 views

How to get sum of values in column based on variables in other column separately? [duplicate]

I have a table data like below abc 1 1 1 bcd 2 2 4 bcd 12 23 3 cde 3 5 5 cde 3 4 5 cde 14 2 25 I want the sum of values in each column based on variables in first column and ...
0
votes
3answers
188 views

Sum of command line arguments?

How would I create a bash script that the user can use to sum any amount of command line arguments, but it will also ignore incompatible arguments? For example, say my script is called sum: sum 10 -...
2
votes
4answers
144 views

Compare the numbers in text file, if meets the condition run a shell script

I have a text file (created by a script) which contains only numbers in a single line like "5 17 42 2 87 33". I want to check every number with 50 (example), and if any of those numbers is greater ...
0
votes
1answer
291 views

Grepping lines which have range of number

I have few lines in my text file as below. I want to grep all the lines which have patterns like :100, :101 and :102 up to :199 . How to get those lines instead of searching like this. :100\|:101\|:...
-1
votes
4answers
31 views

Multiplying digits inside numbers based on position of digit

I have list of numbers like this: 0987656787689 2345453326780 3453212332345 1324532449876 1234532444568 3245321343456 1324354532376 1234532153457 I would like to sort the numbers based on the ...
0
votes
1answer
92 views

Normalizing columns in a table using AWK

I have table of numbers, I want to normalize the table as following: 1- Multiplying column 3 and 7 then add the result to column 11 and multiply the last result with column number 1. 2- Then I want ...
6
votes
2answers
314 views

Extract lines containing certain value or greater

I am working with a log file that contains entries that appear like this: $Hostname1: 0x7FDBF4B1AB10 ( 23698) waiting 100 seconds, NSDThread: for I/O completion on disk vd4 $Hostname2: ...
0
votes
2answers
69 views

converting table with positive and negative values to absolute values

I have data saved in matrices that can be used for statistical analyses. For the purposes of my analysis I need to include all numbers in absolute values other wise the algorithm will fail. sample of ...
1
vote
3answers
94 views

How to ignore differences between negative signs of numbers in the diff command?

I have two large files consisting mainly of numbers in matrix form, and I'd like to use diff (or similar command) to compare these files and determine which numbers are different. Unfortunately, ...
3
votes
2answers
65 views

How do I grep for occurences of “[numberLargerThan5000]ms”?

I have a .log file where each entry is on the form 2018-09-28T10:53:48,006 [Jetty-6152 ] INFO [correlationId] my.package.service:570 - Inbound request: 1.2.3.4 - GET - 12342ms - 200 - /json/some/...
0
votes
2answers
147 views

Convert binary strings into decimal

I want to process with a bash script a text file that looks like this: ADD $05 $05 $05 SUBI $06 $06 00011 MUL $07 $07 $07 JSR 011101 taking the binary numbers (that are always ...
1
vote
2answers
40 views

Appending lines with incrementing numbers to a file

I have a text file, and I would like to add lines to the file arranged as follows; #define ICFGx 0x2y where x is a decimal number that begins at 0 and ends at 255, incrementing by 1 with each ...
7
votes
12answers
720 views

How to collapse consecutive numbers into ranges?

Given a sorted input file (or command output) that contains unique numbers, one per line, I would like to collapse all runs of consecutive numbers into ranges such that n n+1 ... n+m becomes n,n+m ...
0
votes
4answers
80 views

Get numeric value of cat output

When I save result of cat to the variable I get the following: wfpd=$'16213\r' How can I convert this result to numeric value in order to use it as an argument to another command
0
votes
4answers
129 views

Replacing part of a string with countdown numbers using the command sed [closed]

I have a string: TestTest12312313. I would like to replace the number 13 in this string with countdown numbers -1,-2,-3,-4, .... using the command sed, so the output is as follows: TestTest123123-1 ...
0
votes
3answers
51 views

How do I extract a number from a row

31400 371 2946 3966 12378 82 185 206 46 1 I want to write a script that will always extract the second number from a script like the one above i.e. 371. The number ...
-5
votes
3answers
411 views

how to convert MB to BYTE using bash / awk

we need to calculate BYTE value from MB values example 10 --> 10485760 100 --> 104857600
4
votes
1answer
870 views

How to sort lines by float number

I've such a file: name: xxx --- time: 5.4 seconds name: yyy --- time: 3.2 seconds name: zzz --- time: 6.4 seconds ... Now I want to sort this file by these float numbers to generate a new file as ...
11
votes
7answers
4k views

Grep lines starting with 1, but not 10, 11, 100 etc [duplicate]

I have a file of genomic data with tag counts, I want to know how many are represented once: $ grep "^1" file |wc -l includes all lines beginning with 1, so it includes tags represented 10 times, 11,...
1
vote
4answers
207 views

Difficult grep. How can I isolate this number?

I have this file content: 63 41,3,11,12 1 31,60,72,96 7 41,3,31,14,15,68,59,60 7 60,72,96 7 60 1 41,3,31,31,14,15,68,59,60 60 41,3,115,12,13,66,96 1 41,3,11,12,13,66,96 I ...
3
votes
4answers
915 views

Converting awk printf string to decimal

Task: stdout the load avg from top in a decimal form like (e.g 0.23) Details: I need to parse this script to Chef's inspec and check if its result is bigger/smaller than something, for example: ...
2
votes
6answers
973 views

Convert a list of decimal values in a text file into hex format

I have a need to convert a list of decimal values in a text file into hex format, so for example test.txt might contain: 131072 196608 262144 327680 393216 ... the output should be list of hex ...
0
votes
2answers
86 views

Remove and replace column

I have a file which looks like this: 1 1 2 5.24 3 12.46 4 21.56 and so on. I need to change it to: 1 1 3 5.24 5 12.46 7 21.56 on a quick way. So the first column has to have odd values 2i+1 for i ...
3
votes
2answers
59 views

Find the smallest set of values where at least one value is present in every row of a file

I have a file df like: 1 4 1 6 1 7 1 10 2 3 2 9 2 10 3 4 4 7 9 10 I need to identify the smallest set of values such that every row in df contains at least one of these values. ...