Questions tagged [numeric-data]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4 votes
5 answers
337 views

Converting HEX to DEC is out of range by using `mawk`

When the hex number is relative small, I can use echo 0xFF| mawk '{ printf "%d\n", $1}' to convert hex to dec. When then hex number is huge, mawk does not work any more, e.g. echo ...
user avatar
  • 228
0 votes
2 answers
267 views

Matching numbers with glob pattern

I am trying to match using a glob pattern. But it is failing when using myfun 12. dgt='^+([0123456789])$' [[ "$1" == $dgt ]] && echo "SUCCESS" || echo "FAILURE"
user avatar
  • 13
2 votes
1 answer
122 views

What's the difference between "sort -n" and "sort -g"?

What is the difference between the two sort options -n and -g? It's a bit confusing to have too much detail but not enough adequate documentation.
user avatar
4 votes
3 answers
553 views

Random number output between two ranges linked together

This question is about generating random numbers between a range, which is fine, but it doesn't fit my case. I'll explain in SQL terms because it seems to me that's easier to understand, though the ...
user avatar
0 votes
0 answers
26 views

Check if variable in numeric in a bash script [duplicate]

Is this the way to check a variable in numeric? case "$var" in ( +([[:digit:]]) ) cn="$var" ;; (*) cn=208 ;; esac
user avatar
  • 155
0 votes
1 answer
62 views

Highlight every number that is smaller than all previous numbers in the last column

Input: network-snapshot-000000 time 6m 40s fid50k_full 34.9546 network-snapshot-000201 time 6m 52s fid50k_full 30.8073 network-snapshot-000403 time 6m 51s ...
user avatar
  • 295
2 votes
1 answer
77 views

Reformat number in specific column

I have semicolon delimited data, where third column is decimal number: A;B;1234.56 C;D;789.23 I need to make 2 changes to the format of the number: remove numbers after the decimal point add "...
user avatar
1 vote
1 answer
120 views

Sort the data to plot a circle

Here I have a data which I would to plot with line using Gnuplot. Using the code pl 'Sphere_ISOTEST_data.txt' w p I get below figure but, using pl 'Sphere_ISOTEST_data.txt' w l I get the following: ...
user avatar
2 votes
2 answers
724 views

How assign numbers range into a simple bash variable

How assign numbers sequence into bash variable as this fail: $ n={0..9}; echo $n {0..9} $ n=\"{0..9}\"; echo $n "{0..9}" $ eval n={0..9}; echo $n $ eval n=\"{0..9}\"; ...
user avatar
0 votes
3 answers
73 views

Extract maximum values for each objects from a file [duplicate]

I need to extract some values from a file in bash, on my CentOS system. In myfile.txt I have a list of objects called Info_region in which each object is identified with a code (eg. BARD1_region_005 ...
user avatar
2 votes
3 answers
1k views

How to generate a comma separated list of random ints

I am trying to generate a comma separated unordered list of ints between 1 and 10, I have tried the following but it results in an ordered list: seq -s "," 10 | shuf
user avatar
  • 23
7 votes
2 answers
334 views

Can `awk` sum a column over a specified number of lines

I've reviewed the "Similar questions", and none seem to solve my problem: I have a large CSV input file; each line in the file is an x,y data point. Here are a few lines for illustration, ...
user avatar
  • 2,079
0 votes
1 answer
38 views

shell script set the default numbers as double digit zero as prefix [duplicate]

In a shell script, I'm processing, some addition process will print an output. If it is a single-digit one, then it has to add zero as a prefix. Here is my current script: c_year=2020 for i in {01..11}...
user avatar
0 votes
2 answers
112 views

shell script set the default numbers as double digit zero as prefix

In a shell script, I'm processing, some addition process will print an output. If it is a single-digit one, then it has to add zero as a prefix. Here is my current script: c_year=2020 for i in {01..11}...
user avatar
0 votes
8 answers
143 views

Insert Zero Before and After a data point

I need a script that inserts a zero before and after each data point. I am trying to do this in Ubuntu. Example: 1 2 3 4 5 What I need: 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0
user avatar
0 votes
2 answers
196 views

Rounding numbers of a CSV file, skipping the header

This question is a derivative of the https://askubuntu.com/questions/601149/is-there-a-command-to-round-decimal-numbers-in-txt-files, which was successfully solved by using: perl -i -pe 's/(\d*\.\d*)/...
user avatar
  • 93
1 vote
3 answers
684 views

Extracting numbers between two string patterns

I have a file with following type of expression in every line "Age=22 years and Height=6 feet", I want to extract Age and height numbers only. I have tried grep -oP '(?<=Age=)[^years]+' $...
user avatar
3 votes
3 answers
421 views

Calculating rates / 'derivative' with awk

awk newbie here. Suppose I have two columns of data, and I want to calculate the rate of increase, given by delta(y)/delta(x). How would I do this in an awk script? What I've learnt so far only deals ...
user avatar
2 votes
1 answer
195 views

Testing if a string is a number

That should be easy, just use [[ "$var" =~ '^[1-9][0-9]*$' ]]. But I don't get the behavior I expect excepted with zsh. I don't control the machine where the script will be run, so portability along ...
user avatar
  • 2,198
4 votes
2 answers
293 views

Numerical sorting of every column in a file individually using awk

I'm trying to numerically sort every column individually in a very large file. I need the command to be fast, so I'm trying to do it in an awk command. Example Input: 1,4,2,7,4 9,2,1,1,1 3,9,9,2,2 5,...
user avatar
  • 801
4 votes
3 answers
1k views

Number formatting and rounding issue with awk

I want to get the exact number when I try to find the average of a column of values. For example, this is the column of input values: 1426044 1425486 1439480 1423677 1383676 1360088 1390745 1435123 ...
user avatar
  • 349
1 vote
2 answers
659 views

Sum of large numbers and print the result with all decimal points for the stated question when using awk arrays

I have a below input file which I need to split into multiple files based on the date in 3rd column. Basically all the same dated transactions should be splitted into particular dated file. Post ...
user avatar
  • 83
0 votes
4 answers
154 views

Filling empty cells and making data type the same in a tab separated file

I am dealing with a tab separated file with nearly 200MM rows on Linux. In one the columns which contains binary values, I noticed the data type is not consistent and there is a large number of ...
user avatar
  • 109
3 votes
3 answers
292 views

Delete duplicate lines in file without creating new file in ubuntu

I can't seem to find a command that lets me delete duplicates in my file without creating a new file and also preserving the order of the contents in my file. Would there be another command besides ...
user avatar
  • 29
0 votes
2 answers
56 views

Find max values within Column 1 range and print column2

I have a representative dataset 35.5259 327 35.526 326 35.526 325 35.5261 324 35.5262 323 35.5263 322 35.5264 321 35.5265 320 35.5266 319 35.5268 318 # ...
user avatar
0 votes
2 answers
60 views

How to replace a fix location in each line in a file

I have a file as below, how do I replace the $number (location 19-30) and (location 59-70) with its number in cents. update: All fields are required to stay at the same fixed location. input: ...
user avatar
3 votes
3 answers
534 views

How can I convert a float to ratio?

I would like to convert a float to a ratio or fraction. Do we have the option to convert a float 1.778 to ratio as 16:9 or 16/9 in bash, in a fashion similar to Python's fractions module (Fraction(1....
user avatar
  • 8,645
-1 votes
1 answer
358 views

Hexadecimal color codes grep regex in makefile

So I have a text file containing valid and invalid hexadecimal color codes. I want to be able to filter out the invalid codes and print just the valid ones. For a code to be valid it must have a hash ...
user avatar
  • 1
2 votes
2 answers
42 views

Comparing two columns(numeric) in two different text files

I have two text files with space-delimited fields (03 fields) in Linux environment: File1 : ram-service1.txt RAM used Program 23500 kb firewalld 14780 kb tuned 10140 kb polkitd 5370 ...
user avatar
1 vote
6 answers
4k views

how to extract maximum and minimum value from column 1 and column 2

Dear all I have a big data file lets say file.dat, it contains two columns e.g file.dat (showing few rows) 0.0000 -23.4334 0.0289 -23.4760 0.0578 -23.5187 0.0867 -23.5616 0....
user avatar
  • 67
1 vote
3 answers
700 views

Converting base-6 number to base-2 (binary) using commands or a program

I have a base-6 number generated by rolling a physical six-sided dice and want to convert it into base-2 / binary. Are there built-in commands or programs that can do that for me? If not, what is ...
user avatar
-1 votes
1 answer
714 views

regex (or other way) to find numbers followed by a space

I'm running the following awk '$2 ~ /^[0-9]\s+/ {print($2)}' file >> file1 Not sure how to correct this to only select lines where digits are followed by a space?
user avatar
  • 275
-1 votes
2 answers
55 views

How I can change 01 and 25 in 001 and 025 without change 125 in 0125?

I have a file like this Thomas_4567_01 Luc_2344_125 Ann_5780_25 I would like an outpu like this Thomas_4567_001 Luc_2344_125 Ann_5780_025 How I can change 01 and 25 in 001 and 025 without change ...
user avatar
1 vote
5 answers
202 views

sed/awk: replace numbers in a line after last occurance of '.'

I have the following tcpdump stream: Current: 07:36:03.848461 IP 172.17.3.41.33101 > 172.17.3.43.17408: UDP, length 44 07:36:03.848463 IP 172.17.3.42.33101 > 172.17.3.43.17409: UDP, length 44 ...
user avatar
  • 23
4 votes
2 answers
89 views

Why does gawk (sometimes?) think 2.0e-318 > 2.0?

I am trying to find the maximum value of a column of data using gawk: gawk 'BEGIN{max=0} {if($1>0+max) max=$1} END {print max}' dataset.dat where dataset.dat looks like this: 2.0 2.0e-318 ...
user avatar
3 votes
2 answers
307 views

Sort numerical column

I'm trying to sort a file based on a particular position but that does not work, here is the data and output. ~/scratch$ cat id_researchers_2018_sample id - 884209 , researchers - 1 id - 896781 , ...
user avatar
0 votes
5 answers
502 views

Max, Mean, Min for range within column of data

I have data structured like this :- X 43808873 A 14 X 43808874 G 7 X 43808875 T 15 X 43808876 A 13 X 43808877 T 4 X 43808878 C 13 X 43808879 T 11 X ...
user avatar
-1 votes
1 answer
47 views

sum the values of all occurrences parameters

we have the following file , in file we can see the same parameters names with their values more file.txt gg_ff_rr =56 gg_ff_rr =56 gg_ff_rr =52 jk_ll_tt=24 jk_ll_tt=24 jk_ll_tt=24 pl_pl_uu=10 ...
user avatar
  • 10.9k
1 vote
1 answer
210 views

how to change color of text based on value?

I want to use cat to display a file content and changes the text color to red if the number is larger than 50. Example: cat file1 would give 1 33 56 the number 56 will be displayed in red ...
user avatar
2 votes
2 answers
242 views

How to get max, min, and mean from values in column 4

I have data structured like this X 43808504 G 1 ^]. < X 43808505 C 3 . 4 X 43808506 T 8 . ? X 43808507 G 5 . C I want to get the max (8), min (1), and ...
user avatar
0 votes
1 answer
435 views

Calculating average in awk based on several column conditions in csv

I currently have the following csv format, it's much larger but I've taken a chunk of it for now. EV,"Houston","-7.0" AB,"Boston","19.0" OO,"Mystic","13.0" AB,"Boston","-12.0" EN,"New York City","9....
user avatar
3 votes
1 answer
400 views

Awk inconsistent behavior filtering scientific notation numbers

I recently found that for some very small values, filtering using AWK doesn't seem to behave correctly. As in the following file test_loc.txt: 10:10000018 10 0.4505 X:99997421 X 0.95508 X:99997626 ...
user avatar
  • 31
1 vote
3 answers
86 views

Find the maximum value of Column3 and print the values of Column1 and 2 only

In Unix, I am trying to find a command that would find the maximum value in Column3 and print the corresponding values from Column2 and Column1 (but not from Column3) in a new file. Column1 ...
user avatar
0 votes
1 answer
20 views

re-write column's values to obtain previous line's value if exceed number 1

I have a file containing the following list of numbers: 0.1131492 0.1231466 0.1327564 0.1017683 5.4356130 0.1360532 5.4258129 0.1433982 0.1124752 . . . I would like to re-write this list of numbers ...
user avatar
0 votes
1 answer
346 views

Sort file by row and with scientific numbers

I have a file F.tsv with 13 columns, the last column (the 13th columns) looks like this: 2.1e-06 0.58 10 8.7e-22 0.0014 0.034 9.5 0.67 0.67 0.68 9.2 8.4e-22 9.7 I've tried sort -k 13 F.tsv but it ...
user avatar
1 vote
5 answers
4k views

Sum of even and odd numbers of odd and even lines

I would like to write a shell script program that gives the sum of even and odd numbers in a given file's odd and even lines. I would like to use: sed -n 2~2p and sed -n 1~2p but I am not even ...
user avatar
  • 113
0 votes
1 answer
81 views

Compare two lines using second columns

http://0-0.latam.corp.yahoo.com/ 6656 http://0-0.latam.corp.yahoo.com/nonEtAk 6670 http://1.avatar.yahoo.com/ ...
user avatar
0 votes
3 answers
60 views

how to read file line by line and delete the line have number less than 20% shell scripting

i need help. i have this file i want read it line by line with for loops and delete the line less than 20% the number will with list %CPU . %CPU PID USER UID COMMAND %MEM 71 9136 ...
user avatar
  • 1
2 votes
3 answers
457 views

Generates random numbers with 11 digits

I need a command that generates random numbers with 11 digits. How can this be done?
user avatar
4 votes
4 answers
351 views

How can I adjust nth number in a line?

File contents: RANDOM TEXT num1=400 num2=15 RANDOM TEXT RANDOM TEXT num1=300 num2=10 RANDOM TEXT RANDOM TEXT num1=200 num2=5 RANDOM TEXT I would like to subtract 5 for ...
user avatar
  • 2,417

1
2 3 4 5