【发布时间】:2021-05-17 00:04:04
【问题描述】:
我有以下 input.txt 文件
service commands 1 description 'Desc 1 patternid com3'
service commands 2 description 'Desc 1 patternid com3 from err1'
service commands 3 description 'Desc 2 patternid com3 from err2'
service commands 4 description 'Desc 2 patternid com3 from err3'
service commands 1000 description 'to value1 patternid from 1000'
service commands 1001 description 'to value1 patternid from 1001'
service commands 2000 description 'Desc 3 patternid com'
service commands 2001 description 'Desc 3 patternid com2 from err1'
service commands 2002 description 'Desc 4 patternid com2'
service commands 2003 description 'Desc 4 patternid com2 from err1'
service commands 4000 description 'output patternid to com1'
service commands 5000 description 'input to com1'
service commands 6000 description 'input to com2'
我希望使用 awk 从服务命令编号满足 1-1000 到 2000-4000 之间的条件的行中获取唯一描述 但我只想要“patternid”一词之前的描述文本
我在搜索中找到了这个
awk -F'_' '($1>1999 && $1<4000){print}' input.txt
但我无法在第三个字段中搜索多个值
我可以用
打印描述awk -F"service commands |description |'" '/service commands/ && /description /{for(i=1; i<=NF; ++i) printf"%s", $i ; print""}' input.txt
但这不是我想要的
我的愿望输出是
Desc 1
Desc 2
Desc 3
Desc 4
我怎样才能用一个 awk 命令或它们的组合来做到这一点?
【问题讨论】:
标签: awk