ファイルから一致する整数を収集して保存します。

ファイルから一致する整数を収集して保存します。

以下を含む結果ファイルがあります。

==============================================
------------------------------
Begin SimulationInterface Evaluation    1
------------------------------
Parameters for evaluation 1:
                     -1.8961789208e+00 x1
                     -1.3853582017e+00 x2

Direct interface: invoking function 

Active response data for SimulationInterface evaluation 1:
Active set vector = { 1 }
                      2.4892772154e+03 response_fn_1

------------------------------
Begin SimulationInterface Evaluation    2
------------------------------
Parameters for evaluation 2:
                      3.7988695564e-01 x1
                      1.5859091288e+00 x2

Direct interface: invoking function 

Active response data for SimulationInterface evaluation 2:
Active set vector = { 1 }
                      2.0820416317e+02 response_fn_1

==================================

今、結果ファイルから整数、、、およびをx1別々x2のファイルに抽出したいと思います。行を使用して抽出するには、次のようにします。response_fn_1testx1x2

sed -n '/評価パラメータ/{n;p;n;p}'initial.log

合計が表形式にtestなるように、行の整数を出力ファイルにどのように転送できますか?x1x2

x1                     x2
-1.8961789208e+00      -1.3853582017e+00
3.7988695564e-01        1.5859091288e+00

ベストアンサー1

すべてのタスクを実行するには、awkを使用することをお勧めします。

$ awk '
    BEGIN {OFS="\t"; print "x1", "x2", "response_fn_1"} 
    $2 == "x1" {x1 = $1} 
    $2 == "x2" {x2 = $1} 
    $2 == "response_fn_1" {print x1, x2, $1}
' file | column -t
x1                 x2                 response_fn_1
-1.8961789208e+00  -1.3853582017e+00  2.4892772154e+03
3.7988695564e-01   1.5859091288e+00   2.0820416317e+02

パイプスルーはcolumn -tきれいな印刷にのみ使用されます。 awk 出力自体はタブで区切られます。

おすすめ記事