Skip to main content

Questions tagged [numeric-data]

2 votes
1 answer
234 views

Do `[[ ]]` and `(( ))` have "transitive evaluation" of variables?

I am using bash, version: GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) I made a following script: #!/usr/bin/bash a=11 b=4 c=7+b if [[ a -eq c ]] then echo "ok" else ...
Yakog's user avatar
  • 517
-3 votes
2 answers
73 views

Error parsing memory value in bash script: expected integer expression

I have the following script to check free memory, #!/bin/bash THRESHOLD="500" FREE_MEM=$(free -mh | awk '/^Mem:/{print $4}') if [ "$FREE_MEM" -lt "$THRESHOLD" ]; then ...
Be_developer 's user avatar
8 votes
5 answers
2k views

How to round to 2 decimals in bash like MS Excel does?

I spent hours in searching how to round "floating numbers" in BASH but couldn't find any correct! solution :( If I put these numbers to Excel, then I will receive the correct results after ...
user3719454's user avatar
0 votes
2 answers
101 views

CSV output for Number data

Below is a tab delimited sample. When I open this file with notepad it looks good for numbers. But if I open it with excel, numbers do not look correct. They look +11 at the end but inside if I ...
codecheck123's user avatar
-1 votes
2 answers
553 views

Test for a number in bash [duplicate]

Is this the correct way to test for a number, with double [[]] enclosing :digit: and single quotes surrounding the regex ? if [[ "$var" =~ '^[[:digit:]]+$' ]]; then
Vera's user avatar
  • 1
0 votes
0 answers
26 views

numeric sort with unique option does not show 0! [duplicate]

I have a file with many redundant numbers in each row. Imagine something like the below: echo "10 9 5 6 4 cell 3 2 0 7 0 1" > test When I use sort -un test I get the following output: ...
javadr's user avatar
  • 131
0 votes
2 answers
510 views

Add commas in place of number with sed?

Trying to write a simple script to fetch ethereum price and format the response. Here is what I've tried: #!/bin/bash response=$(curl 'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=...
ash's user avatar
  • 1
2 votes
1 answer
506 views

How do I use sort on multiple columns with different data types

Here's my tab-delimited file t.tsv: $ cat t.tsv 2022/05/05 -258.03 2022/05/07 -18.10 2022/05/09 -10.74 2022/05/09 -132.60 2022/05/12 -18.56 2022/05/12 -20.20 2022/05/17 -11.00 2022/05/17 -112....
Chap's user avatar
  • 389
2 votes
0 answers
68 views

Scientific notations to specific scientific notation [duplicate]

I want to convert the value from 1.759114e-07 to 175.9114e-09. How can I script the conversion? I tried this but I'm not getting what I want (which is 175.9114e-09): $ echo 1.759114e-07 | awk '{printf(...
Ahamad Ahamad's user avatar
0 votes
1 answer
102 views

How to display only the content between opening and closing tags in XML file?

How to search the XML file using grep or similar for a particular tag but show only the content between opening and closing tags? Here is the exact tag I'd like to locate: <max-diskusage>...
Joey's user avatar
  • 199
3 votes
3 answers
1k views

How to sort each 20 lines in a 1000 line file and save only the sorted line with highest value in each interval to another file?

I have a file that has 1000 text lines. I want to sort the 4th column at each 20 lines interval and print the output to another file. Can anybody help me with sorting them with awk or sed? Here is an ...
Sanjukta's user avatar
0 votes
2 answers
528 views

Finding values of one file within range of another file and selecting the top value

I have two files A and B. File-A has 4 columns and 600,000 rows. File-B has 4 columns and 5000 rows. Example: File-A: ENSB1 1 12245 0.53 0.002 ENSB2 1 13400 0.27 0.0003 ENSB3 1 14780 0.13 0.00001 ...
Muhammad Sajid Tahir's user avatar
4 votes
5 answers
1k 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 ...
John's user avatar
  • 318
5 votes
1 answer
3k 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
1k 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 ...
schrodingerscatcuriosity's user avatar

15 30 50 per page
1
2 3 4 5
17