Hello Experts,
I have .txt file which has various columns and 4 rows.
cat input.txt
Cont x y z k
Max 0.3 0.9 0.4 0.6
Min 0.2 0.9 0.3 0.6
Diff 0.1 0 0.1 0
Output:
Cont x y z k
Max 0.5 1.1 0.6 0.8
Min 0.1 0.7 0.2 0.4
Diff 0.4 0.4 0.4 0.4
That means if the diff between the Max and Min is 0.1 than add 0.2 to max value and subtract 0.1 to min value, if diff is 0 than add 0.2 to max and subtract 0.2 to min value. I had to code this in csh script since this script will be part of bigger script written in csh.
Thanks in advance.
Use awk; that way you can incorporate it into any script, even one written in csh
awk '
NR == 1 { print }
NR == 2 { cols1 = split($0,max) }
NR == 3 { cols2 = split($0,min) }
NR == 4 { cols3 = split($0,diff) }
END {
### do the calculations on the elements of the arrays
### and print the results (gotta run, sorry)
}
' input.txt