有没有办法在单个管道命令链中有效地组合以下两个UNIX命令?

时间:2020-01-25 03:09:54

标签: unix awk sed rpm

问题陈述

  1. 我想使用rpm -qi ${pkgName}来识别包装及其说明。
  2. (1)输出上的
  3. cat -n将向我显示病房中的哪一行 说明部分开始。

    Ex:-第15行,以rpm为单位的原子IDE编辑器。

  4. 我知道我可以使用该行号再次解决输出和格式化部分 rpm -qi atom | awk -v n=${lineNum} 'NR>=n'。这里lineNum为15。

这效率低下,我只想使用rpm -qi命令一次,然后将其提取出来,以实现对病房的描述。有人有办法吗?

其他要求的输入

[anand@ldnpsr2937 ~]$rpm -qi atom
Name.       : atom
Version     : 1.42.0
Release     : 0.1
Architecture: x86_64
Install Date: Sun 12 Jan 2020 10:23:12 AM
Group       : Unspecified
Size        : 590646918
License     : MIT
Signature   : (none)
Source RPM  : atom-1.42.0-0.1.src.rpm
Build Date  : Sat 14 Dec 2019 03:38:56 AM
Build Host  : 2580f855e2eb
Relocations : /usr
URL         : https://atom.io/
Summary     : A hackable text editor for the 21st Century.
Description : 
A hackable text editor for the 21st Century.
[anand@ldnpsr2937 ~]$

2 个答案:

答案 0 :(得分:5)

使用rpm命令来查询特定标签,而不是组合某些内容。根本不需要sed和花哨的东西。

rpm -q --queryformat '%{description}' atom

答案 1 :(得分:1)

您可能想要类似的东西:

rpm -qi atom | sed -ne '/^Description/,$ p'

我们使用sed在匹配行之后打印所有内容的位置。但是,正如另一个答案所示,rpm有一种实现此目标的本地方法。