【发布时间】:2020-10-29 06:51:22
【问题描述】:
我在lists.txt 文件中有一些内容如下:
abc.com. IN A 10.120.51.95 ;10.40.40.57 ;old 10.20.3.57
;def-mytaxi.com. IN A 10.12.4.9 ;10.40.3.43 ;test
xyz-mytaxi.com. IN CNAME 10.12.4.8 ;10.40.3.53 ;test
所以,我需要将这些写入另一个文件,所以
-
它应该避免任何以
;-2nd row is avoided开头的行 -
它应该只选择带有
IN A-only the 1st row is seletced的行 -
它应该删除每个第一列末尾的训练
.-remove . after abc.com. -
它应该避免 ; 之后所选行中的任何值-
therefore only prints abc.com 10.120.51.95
最终输出应该被写入一个文件,它应该看起来像;
abc.com 10.120.51.95
所以我写了这个脚本,但是除了3rd 和4th 步骤之外,一切都很好。
我得到的输出为:
abc.com. 10.120.51.95 10.40.40.57 old 10.20.3.57
这是我尝试过的,有人可以帮助我吗?
awk '/IN A/ {$2=$3=""; print $0}' lists.txt | sed '/^;/d;s/;//g;s/#//g' > updated_list.txt
【问题讨论】:
-
只是想知道您上一个问题的答案是否对您有用:stackoverflow.com/a/64553314/548225