I would like to replace number between patterns with multiplicated numbers and print the all the lines.
The file is a tree file in newick format and consisted only a single line. My targets are all the numbers after )
and before :
. I wanted to multiply all the numbers in between the two symbols with 100.
file:
((((A_8:0.000846,(A_5:0.002449,(A_1:1e-06,((A_4:1e-06,((A_7:1e-06,A_6:0.001061)0.714000:1e-06,A_3:1e-06)0.314500:1e-06)0.358667:1e-06,A_2:1e-06)0.361000:1e-06)0.434800:1e-06)0.683500:0.001619)0.888571:0.001931,A_9:0.00069)0.688471:0.000691,...
The easiest way to me seemed to be splitting the file by replacing all the ":" symbols with a new line first. So all my target numbers are now in separate lines and appear after )
. Then, I was using the awk script below to multiply the target numbers with 100, but didn't manage to keep the lines without my target number though.
script:
sed 's/:/\n/g' df9.tree | awk -F")" '{OFS=")"} $2=$2*100 {print $0}'
sed 's/:/\n/g' df9.tree | awk '$NF ~/)/ {$NF *=100}1'
How can I multiply the numbers after )
and print the entire file in this case? Or is there other simpler way to directly look for the numbers lie between :
and )
, multiply them by 100 and print the whole file?
Update: Expected output
((((A_8:0.000846,(A_5:0.002449,(A_1:1e-06,((A_4:1e-06,((A_7:1e-06,A_6:0.001061)71.4000:1e-06,A_3:1e-06)31.4500:1e-06)35.8667:1e-06,A_2:1e-06)36.1000:1e-06)43.4800:1e-06)68.3500:0.001619)88.8571:0.001931,A_9:0.00069)68.8471:0.000691,...)
...
s are because the right answer will depend on whether your input file ends with)
alone or)\n
or ends in something else. So please replace the...
s with representative values as they appear in your real input file and if there is no newline at the end then tell us that.