i have many simple text file(with extension .txt) that consists of 6 rows and 7 columns as given below
0.00 5.8 2.0 5.0 6.0 8.0 0.0
10.00 5.8 2.0 1.0 1.0 1.2 9.6
10.00 9.3 2.2 2.0 1.4 2.5 9.6
30.00 9.3 2.2 1.2 1.5 1.9 1.4
30.00 9.3 2.2 3.2 2.4 1.2 4.1
60.00 9.8 3.5 1.4 2.7 3.2 4.5
I want to do some manipulations using column3(row 3,4,5) and column2(row 3,4,5) without disturbing row 1,2 and 6 . Additionally there will be always same number in third,four fifth rows of column 3 and column 2.
At first i want to increase the value of row 3,4,5 of column3 (for example in above text file from 2.2 to 3.4) with step 0.2 for every .txt files and want to multiply it by 1.6 and want to place the multiplied output in column2(row 3,4,5)
For example:
in the original input file column3(row 3,4,5) values are 2.2 but want to increase from 2.2 to 2.4(0.2 increment),then expected output would be
0.00 5.8 2.0 5.0 6.0 8.0 0.0
10.00 5.8 2.0 1.0 1.0 1.2 9.6
10.00 3.84 2.4 2.0 1.4 2.5 9.6
30.00 3.84 2.4 1.2 1.5 1.9 1.4
30.00 3.84 2.4 3.2 2.4 1.2 4.1
60.00 9.8 3.5 1.4 2.7 3.2 4.5
Again increase 0.2 then the expected output would be
0.00 5.8 2.0 5.0 6.0 8.0 0.0
10.00 5.8 2.0 1.0 1.0 1.2 9.6
10.00 4.16 2.6 2.0 1.4 2.5 9.6
30.00 4.16 2.6 1.2 1.5 1.9 1.4
30.00 4.16 2.6 3.2 2.4 1.2 4.1
60.00 9.8 3.5 1.4 2.7 3.2 4.5
i tried the code below:, after referencing text manipulation by addition and multiplication
#!/bin/bash
for file in /home/se/data/*.txt
do
for val in $(seq 2.2 0.2 3.4)
do
awk -vval=$val -vadd=0.2 -vsmul=1.6 '{
if(NR==1 || NR==2) {
$3=val;
$2=$3
} else if(NR>=3 && NR<=5) {
$3=val+add;
$2=$3
} else $3=$3;
print
}' test_file > output$val
done
done
But i am getting some error,hppe somebody will come forward to help me.Thanks.