问题:
有的行有括号,有的行有一组括号(),有的行有两组括号()(),每个括号内有两个数字,有逗号隔开。提取括号内的两个数字,用空格分开。原来一个括号里的两个数字要占一行。附件是一个待处理文本。
例如文本
---------------------------------
80.0000000000000 8.00000000000000 4.00000000000000
4.00000000000000 24.0000000000000 1.00000000000000
0.000000000000000E+000 0.000000000000000E+000 0.000000000000000E+000
1.333333333333333E-002
-9.03196517310970 1.99999999999800 5.90361146269155
1.99999999999800 5.90361231235872 1.99999999999800
5.90361231235875 1.99999999999800
10.2858284013301 0.000000000000000E+000
(-3.580654501620760E-010,-1.784472163625327E-009)
(0.225066057852569,-0.165873834696735) (0.325505768511269,-9.488556897954557E-002)
------------------------------------------------------------------------------------------------
提取后变成
-3.580654501620760E-010 -1.784472163625327E-009
0.225066057852569 -0.165873834696735
0.325505768511269 -9.488556897954557E-002
解答:
awk ‘/\(/{gsub(/[(),]+/," ",$0);if($3)print $1,$2"\n"$3,$4;else print $1,$2}‘ file
-3.580654501620760E-010 -1.784472163625327E-009
0.225066057852569 -0.165873834696735
0.325505768511269 -9.488556897954557E-002