我有一个文件“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
你能给我一个可行的解决方案吗?
最佳答案
尝试:
awk '/Point ID/{sub(/.*\./,"",$3);VAL=$3;next} /^value/{print VAL,$2}' Input_file
说明: 查找其中包含字符串“point ID”的行,然后将其第 3 个字段替换为 DOT 并将其保存到名为 VAL 的变量中,然后使用next 将跳过 awk 的所有进一步语句。现在 ^Value 将检查从它开始的行/记录,如果是,那么它将简单地打印变量 VAL 的值以及它的第二个字段值。
关于linux - 使用 awr Linux Red Hat 从文件中列出字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44889272/