使用awr Linux Red Hat从文件中列出字符串

时间:2017-07-03 15:27:14

标签: linux shell scripting awr

我有一个文件“salida_test”包含(重复方式):

Point ID   1.750251
 Point Name >BRI_4L_SA2__INT Interruptor 33kV Parque Industrial              <
 value 2
 Time of last value update   (ascii): >03/07/17 11:11:14.596 ART<
 TLQ   0000000c00004000
 station #79    abbr: >BRI         <  full: >E.T. BRIGADIER LOPEZ            <

 Point ID   1.140147
 Point Name >RUF_5BC1____INT Int. Banco Cap. 1 13.2kV                        <
 value 2
 Time of last value update   (ascii): >03/07/17 10:27:58.495 ART<
 TLQ   0000000c00800000
 station #18    abbr: >RUF         <  full: >E.T. RUFINO   

              <

我需要以这种格式提取行:

Point ID   1.750251  value 2    --> in the same line
Point ID   1.140147  value 2    --> in the same line

然后再次过滤:

750251 2
140147 2

我有一个部分过滤器,但我无法获得解决方案:

awk '(/Point ID/ || /hi/)' salida_test

所示:

 Point ID   1.750251
 Point ID   1.140147

awk '(/value/ || /hi/) && !/Time of last value/' salida_test

所示:

value 2
value 2

你能给我一个可行的决议吗?

1 个答案:

答案 0 :(得分:0)

尝试:

awk '/Point ID/{sub(/.*\./,"",$3);VAL=$3;next} /^value/{print VAL,$2}'  Input_file

说明: 寻找包含字符串&#34;点ID&#34;的行然后在其中替换它的第三个字段直到DOT并将其保存到名为VAL的变量,然后使用next将跳过awk的所有进一步语句。现在^ Value将检查从它开始的行/记录,如果是,那么它将仅用它的第二个字段值打印变量VAL的值。