bash脚本:(数据提取)使用awk sed grep或任何有用的命令来提供建议

时间:2017-06-23 04:26:58

标签: bash data-extraction

这是我输入文件的一部分。我需要提取数据。具体来说,我想提取部分逸度:单位[bar]。我把这些价值变得大胆。告诉我该怎么做?

Component 0 [hexane] (Adsorbate molecule)
    Partial pressure:      5000.00000000000000 [Pa]
                             37.50000000000000 [Torr]
                              0.05000000000000 [bar]
                              0.04934616333580 [atm]

    Fugacity coefficient:       0.9986883219 [-]

    Partial fugacity:      4993.44160943095812 [Pa]
                             37.45081207073218 [Torr]
                              ***0.04993441609431 [bar]***
                              0.04928143705335 [atm]
Component 1 [22-dimethylbutane] (Adsorbate molecule)
    Partial pressure:      5000.00000000000000 [Pa]
                             37.50000000000000 [Torr]
                              0.05000000000000 [bar]
                              0.04934616333580 [atm]

    Fugacity coefficient:       0.9988647141 [-]

    Partial fugacity:      4994.32357042947660 [Pa]
                             37.45742677822107 [Torr]
                              ***0.04994323570429 [bar]***
                              0.04929014133165 [atm]

2 个答案:

答案 0 :(得分:1)

只有1个命令:

awk '/fugacity/ { getline; getline; if ($2 == "[bar]") print $1 }' file.txt

从您的问题和示例中不是很清楚,但如果您只想要第一个

awk '/fugacity/ { getline; getline; if ($2 == "[bar]") {print $1; exit} }' file.txt

答案 1 :(得分:0)

未测试:

cat {file} |grep -A 3 fugacity| grep bar| awk -F" " '{print $1}'