0

我有这些数据行。我只想打印 A、C 和 D 后面的数字。有没有办法打印这些列?

 (((A 0.0400213  B 0.0400213  0.00737467  C 0.047396  0.03466  D 0.082056 ;
 ((C 0.0275027  (A 0.023266  B 0.023266  0.00423667  0.0131187  D 0.0406213 ;
 ((C 0.0310553  (B 0.0210907  A 0.0210907  0.00996467  0.0222647  D 0.05332 ;
 ((C 0.03491  (A 0.020474  B 0.020474  0.014436  0.0221067  D 0.0570167 ;
 ((C 0.0485573  (A 0.00938133  B 0.00938133  0.039176  0.00335133  D 0.0519087 ;

如果我想获得 A 之后的数字,
我的预期结果将是:

0.0400213,
0.023266,
0.0210907,
0.020474,
0.00938133
4

2 回答 2

3

GNU 的代码:

$sed -r 's/.*(A\s)([0]\.[0-9]+).*/\2/' 文件
0.0400213
0.023266
0.0210907
0.020474
0.00938133
于 2013-06-26T19:07:52.277 回答
3

这应该有效:

awk '{for(i=1;i<=NF;i++) if($i~/A|C|D/) printf $++i FS; print ""}' file

输出:

$ awk '{for(i=1;i<=NF;i++) if($i~/A|C|D/) printf $++i FS; print ""}' file
0.0400213 0.047396 0.082056 
0.0275027 0.023266 0.0406213 
0.0310553 0.0210907 0.05332 
0.03491 0.020474 0.0570167 
0.0485573 0.00938133 0.0519087 

更详细:

$ awk '{for(i=1;i<=NF;i++) if($i~/A|C|D/) { gsub(/[(]/,"",$i) ; printf $i " is " $++i FS }; print ""}' file
A is 0.0400213 C is 0.047396 D is 0.082056 
C is 0.0275027 A is 0.023266 D is 0.0406213 
C is 0.0310553 A is 0.0210907 D is 0.05332 
C is 0.03491 A is 0.020474 D is 0.0570167 
C is 0.0485573 A is 0.00938133 D is 0.0519087 

更新:

$ awk '{for(i=1;i<=NF;i++)if($i~/A/){gsub(/[(]/,"",$i);print $++i}}' file
0.0400213
0.023266
0.0210907
0.020474
0.00938133
于 2013-06-26T14:50:27.903 回答