Linked Questions

0
votes
1answer
153 views

Can i use & variable of sed for doing operation inside $()? [duplicate]

I am not sure whether the below statement can be done placing & inside $() so that each time & is replaced by 1,2,3,4 and 1 is added to it. echo 1 2 3 4 | tr ' ' '\n' | sed "s/.*/$(echo expr ...
13
votes
4answers
3k views

How to increment the value of a (decimal) variable (with leading zero) by +1?

I have a file in the name of Build.number with the content value 012 which I need to increment by +1. So, I tried this BN=$($cat Build.number) BN=$(($BN+1)) echo $BN >Build.number but here I am ...
8
votes
3answers
6k views

Addition of extremely large numbers in shell script

Suppose that two numbers are stored in two different files, a.txt and b.txt. Each number is large enough (more than 30 digits) to not be supported by the numeric data type used by bash. How may I ...
9
votes
3answers
7k views

Fastest way to sum Nth column in text file

I have a CSV file (in which the field separator is indeed comma) with 8 columns and a few million rows. Here's a sample: 1000024447,38111220,201705,181359,0,12,1,3090 1064458324,38009543,201507,9,0,1,...
7
votes
5answers
606 views

How to add some symbol (or just add newline) if the numbers in the text are not continuous

Ex: Input file A<0> A<1> A_D2<2> A_D2<3> A<4> A_D2<6> A<9> A_D2<10> A<13> Desired Output: A<0> A<1> A_D2<2> A_D2<3> A&...
5
votes
4answers
966 views

Summing rows in a new column using sed, awk and perl?

I have a file that contain numbers something like: 1 11 323 2 13 3 3 44 4 4 66 23 5 70 23 6 34 23 7 24 22 8 27 5 How can I sum the rows and output the results in a column, so the results are as ...
3
votes
5answers
2k views

arithmetic operations within column with awk or sed

I have a file whose columns contain simple arithmetic equations that I would like to merge to the arithmetic result. Input sample (tab-separated columns): +104-1+12 6 +3 I would like to ...
4
votes
3answers
4k views

Sed incremental arithmetic

I want to change a number at the end of a string by incrementing that number by one each time I run a specific sed line. The string looks like this: server-port=25555 I was thinking I could run ...
1
vote
4answers
1k views

Bash script/awk to input and output a CSV file

I'm having some trouble creating a bash/awk/sed script that would take a comma-separated CSV file of three columns (firstname, lastname, date of birth), and outputs another CSV file that has the same ...
1
vote
2answers
1k views

what's the simplest way to increment the numbers in this string 01:02:99 in unix?

What is the simplest way to increment the numbers in this string 01:02:99? Expected output: 01:03:00 I'm hoping for a sed response, but I don't think it would be simple.
0
votes
3answers
1k views

Move the specified string to specific position using sed

How to move the specified string (starting with math) to a specific position (20th column) using sed (with regex)? I want to move the string starting with math to column 20 in every line and the math ...
2
votes
2answers
952 views

Sum of columns for rows containing a specific term

I'm wondering if there is any sed or awk command that can sum all columns for the rows with an identical identifier. For example, my file data.txt is set out as below, except that it contains ~1800 ...
2
votes
3answers
180 views

How to get the average of multiple data in a row from multiple folders

My data inside a folder data looks like data1.txt, data2.txt, … data120.txt. Inside each .txt file I have four columns (1000 data lines in each column) example: data1.txt 1 2 3 4 4 0 1 3 3 1 1 2 2 ...
0
votes
3answers
72 views

I'd like to use one of three commands sed (number ranges)

There is one text file.(test.txt) 1970-01-01 1971-01-01 1972-01-01 1973-01-01 1974-01-01 .... 1993-01-01 1994-01-01 1995-01-01 1996-01-01 ... 2015-01-01 2016-01-01 I would like to clear the line of ...
1
vote
2answers
75 views

Replacing number with the same value (number) of one characters

I have to find all file types using file -b $(find . -type f), sort them into unique categories, and print out top 4 most categories where the number is replaced with equal number of "#". The output ...