我可以仅在一行中打印 RPM 包信息的“描述”字段吗

问题描述 投票:0回答:2

我需要获取一些 RPM 包的信息,然后解析它们,所以我使用

rpm -q --qf [FORMAT] [PACKAGE]
命令。

它工作正常,但包的描述字段总是多行,这使我的工作更难以解析。有没有办法让这个字段只在一行上具有特定的格式?

这是我当前的格式字符串:

Name:%{NAME}\nVersion:%{VERSION}\nRelease:%{RELEASE}\nArchitecture:%{ARCHITECTURE}\nInstall Date:%{INSTALLTIME:date}\nDescription:%{DESCRIPTION}\n

linux format rpm
2个回答
1
投票

恐怕答案是否定的,你不能把它写在一行上。描述是多行文本,新行字符由包维护者放置在那里。


0
投票

这可以通过使用 RPM 命令两次的 FOR 命令来完成,然后还进行一些字符串替换以获得您想要的输出。最初,您需要将一个包的所有内容都放在一行上,然后更改输出以将每个查询变量放在一行上。我通过将初始转速输出设置为管道分隔来做到这一点。然后使用 TR 将换行符更改为空格。 然后将管道转换为换行符。

所以一个大的一行命令看起来像这样。

for name in `rpm -qa --qf "%{NAME}\n" openssh-server authconfig`; do rpm -qa --qf "Name:%{NAME}|Version:%{VERSION}|Description:%{DESCRIPTION}|" ${name}|tr '\n' ' '|tr '|' '\n'; done

这将为您提供输出。

Name:openssh-server
Version:7.4p1
Description:OpenSSH is a free version of SSH (Secure SHell), a program for logging into and executing commands on a remote machine. This package contains the secure shell daemon (sshd). The sshd daemon allows SSH clients to securely connect to your SSH server.
Name:authconfig
Version:6.2.8
Description:Authconfig is a command line utility which can configure a workstation to use shadow (more secure) passwords.  Authconfig can also configure a system to be a client for certain networked user information and authentication schemes.

要对所有软件包执行此操作,请相应地更改初始 RPM。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.