Question: Hello Using Bash-Linux I want to write a script where, I input a file (myfile) where there are 4 columns of data: year inf1 inf2

Hello

Using Bash-Linux

I want to write a script where, I input a file (myfile) where there are 4 columns of data:

year inf1 inf2 data

2022 aaaa xxxx 7.2 2022 bbbb zzzz 8.1 2022 cccc vvvv 4.1 2022 dddd ssss 4.1 ...............

2022 eeee www 8.0

I want to redirect to the same file a (5th) column where I calculate the log10 of the 4th column(data). And then from the 5th column I just calculate, I want to add a number, numb (input by the user)

So what I have until know is:

infile="myfile"

awk '{print log($4)/log(10);}' $myfile >> $myfile

awk '{var=($5 + $var) ; print var}' $myfile >> $myfile

So I want in the end to have a file same as the input file (my file) plus two more columns with my calculations.

But my method doesn't work. So how can I direct to the same file. >> tee command doesn't work always and sponge command doesn't work at all.

Any help, please?

Thank you in advance.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!