The tag has no usage guidance.

learn more… | top users | synonyms

2
votes
0answers
54 views

Find the top 5 closest rather than just the closest? [migrated]

How would you find 5 numbers in a column of numbers that are the closest to a $VariableNumber? For example, if the $VariableNumber = 30 then: Example input file: 50 100 70 40 20 10 65 41 92 ...
0
votes
2answers
47 views

copy every line from a text file that contains a number greater than 5000

Hi I've tried many solutions to similar questions and none have seemed to work for me. I have a text file where each line has an undefined length of numbers after the string " length_ ". How can I ...
0
votes
1answer
34 views

How to sum the content of all the files in directory columnwise

I want to add these files column wise i.e. column 1 of file 1 should be added to column 1 of file 2 and so on...., similarly column 2 of file 1 should be added to column 2 of file 2 ...... Col1(...
4
votes
2answers
42 views

Bash - Integer expression expected

I am making the check for update script for my theme I have 2 text files. First one is called "current.txt" and contains the current version. There is 4.1.1 string in that text file. Second one is ...
0
votes
1answer
28 views

How to multiply two columns in a file by a constant number

I have a file like this. input data 4.2394 4.4569 4.2427 4.1011 4.2879 4.1237 4.2106 4.4844 4.2373 4.1071 4.1322 4.0502 4.3103 4.4255 4.4342 4.5262 I need to multiply each element by a constant ...
2
votes
2answers
110 views

Extracting positive/negative floating-point numbers from a string

I am trying to extract numbers out of some text. Currently I am using the following: echo "2.5 test. test -50.8" | tr '\n' ' ' | sed -e 's/[^0-9.]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' This ...
3
votes
3answers
44 views

Proper type casting in a shell script for use with while loop and modulus

I am trying to write a script to get a random, even hex number. I have found the the openssl command has a convenient option for creating random hex numbers. Unfortunately, I need it to be even and my ...
1
vote
1answer
90 views

How to compare a program's version in a shell script?

Suppose I want to compare gcc version to see whether the system has the minimum version installed or not. To check the gcc version, I executed the following gcc --version | head -n1 | cut -d" " -f4 ...
3
votes
5answers
318 views

Increment index in file

Alright, it seems I cannot find a way to do what I need. Let's say I have a text file A like this (freqBiasL2[27]) (SatBiasL1[27]) (defSatBiasL2_L1[27]) (defSatBiasSlope[27]) (...
0
votes
1answer
25 views

How to assign variables associated with list of ranges to another table with integers

I have a list of integers from 1 to 6k, and I have a list of ranges (start/stop) with a third value I'd like to assign to each integer within those ranges. The list of ranges might look like this, ...
2
votes
2answers
42 views

average of specific rows in a file and output in tab-delimited file

I have 6 rows in files. I need to find average only of specific rows in a file and the others should be left as they are. The average should be calculated for A1 and A2, B1 and B2, other lines should ...
0
votes
1answer
54 views

Shell program that outputs the averages

Basically, what I need to do is write a shell program called avgs that would read lines from the file with data, where the title line could be at any line within the data. Hint: You must keep a total ...
1
vote
3answers
122 views

Formatting from Decimal to Exponential

I have a data file abc.txt in the following format: BALT 1 54.500 -161.070 3.95863757 0.01691576 BARM 2 -9.200 67.120 4.07529868 0.01951653 BKSR 3 43.830 142.520 4.08919819 0.00587340 I ...
1
vote
1answer
152 views

How to normalize irregular data values

From a PHP table I get the values graphically represented. However some of the data received is 'damaged' or incorrect thus yielding a non-sensible graphical representation. The hours (y-axis) is ...
1
vote
1answer
94 views

validate the sequence number in the trailer of a file

We have a file that arrives daily and has a sequence number in the trailer like 9999 TR SAP _AP Distribution 0000000000000001 where 0000000000000001 is the sequence number and the file that ...
-1
votes
1answer
79 views

Count of Lines within a Range

I'm trying to do a count of all the values (numeric) in the third column of a file that fall within a specific range of numbers. I've found the min and max but have no idea how to do the count now. I'...
16
votes
10answers
2k views

How can I quickly sum all numbers in a file?

Each line contains text and numbers in one column. I need to calculate the sum of the numbers in each row. How can I do that? Thx example.log contains: time=31sec time=192sec time=18sec time=543sec ...
2
votes
2answers
78 views

Add a number in a huge ASCII file

Background: (1) Here is a screen capture of a part of my ascii file (over 600Mb): (1.1) Here is a part of the code: 0, 0, 0, 0, 0, 0, 0, 0, 3.043678e-05, 3.661498e-05, 2.070347e-05, 2....
2
votes
2answers
333 views

How to extract the positive numbers in the first column from an output as in the question?

I am running Ubuntu 14.04.1 LTS 64-bit with Bash 4.3.11(1)-release I have a program called harminv producing output as follows: $ h5totxt hsli0.126.h5 | harminv -vt 0.1 -w 2-3 -a 0.9 -f 200 # ...
0
votes
2answers
68 views

Take the value of another column if the query column is between two column values

So i have a file with column that has information on salary (eg. 2674 dollars) - indi salary sam 2674 john 6375 max 9547 and another file with the scale of the salary (column1&...
3
votes
1answer
246 views

How to find out the biggest number in many documents that contains different numbers

For example, there are some temperature data at those folders in different time. temps.txt contains the temperature number. So how can I use bash script to find out the maximum temperature? (the ...
1
vote
1answer
212 views

Summing by common strings in different files

I have a file file1 with the amount of times a user shows up in the files, something like this: 4 userC 2 userA 1 userB and I have another file file2 with users and other info like: userC, degree2 ...
2
votes
3answers
845 views

How to sum times in a text file using command-line?

I have a text file containing flight times, hours and minutes separated by colon sign, one per line: 00:50 00:41 00:43 00:50 01:24 I am currently using Apple's Numbers application with a simple ...
3
votes
1answer
2k views

Numeric sort by the column values

For example I have some test file and want to sort it by the column values. After awk -F'[:,]' '{print $16}' test.json I get next output for the column 16: 123 457 68 11 939 11 345 9 199 ...
4
votes
2answers
648 views

Thousands separator in printf in zsh

I have been trying to define a thousands separator in printf for a while now and I have discovered that zsh has some problems with it. In bash I can use something like: $ printf "%'d\n" 1234567890 ...
5
votes
3answers
4k views

Grouped aggregate utility (like SQL GROUP BY)?

Unix has several utilities for performing relational algebra-like operations on streams (grep, join, cut, additional things with awk). Is there a grouped aggregate utility readily available (or ...
7
votes
1answer
4k views

comm: file is not in sorted order

I used comm to compare two sorted files. Each line in these files are positive integer numbers. But the results show comm: file 1 is not in sorted order comm: file 2 is not in sorted order How ...
3
votes
3answers
529 views

Print only lines that are completely numeric

I'd like to filter through a text file and only print the lines where each column is a valid floating point number. For example: 3 6 2 -4.2 21.2 3 x 4.2 21.2 3 2 2.2.2 Only the first line would ...