小编pra*_*tis的帖子

如何在带有 awk 的 shell/终端中使用 for 循环?

命令

dpkg -l | awk '$2=="ufw" {sub("ubuntu[^[:alpha:]]*$", "", $3); print $3"\t"$2}'
Run Code Online (Sandbox Code Playgroud)

输出:

0.34~rc-0   ufw
Run Code Online (Sandbox Code Playgroud)

现在$2=="ufw",我不想像那样指定包名,而是想迭代并获取所有包的列表,如下所示:

2.20.1-5.1   util-linux
1.0.2-1  zerofree
0.34~rc-0   ufw
Run Code Online (Sandbox Code Playgroud)

编辑
自己犯了一个语法错误。我应该直接使用相同的命令,删除$2=="ufw". 答案是dpkg -l | awk '{sub("ubuntu[^[:alpha:]]*$", "", $3); print $3"\t"$2}'

command-line dpkg awk text-processing

2
推荐指数
1
解决办法
224
查看次数

标签 统计

awk ×1

command-line ×1

dpkg ×1

text-processing ×1