[plug] re: awk

Craig Ringer craig at postnewspapers.com.au
Sun Jul 20 20:39:59 WST 2003


> I seemed to recall that there is a way to get a listing of files (in
> this case rpms) where one could use (correct me if I'm wrong) awk to
> limit the output to either the filename only or filename and version
> only.  However I've looked at man awk and awk --help, and I just do not
> understand how it is used.  I would appreciate it if someone could send
> an example with a simple explanation.

"man cut" is an important thing to read for this sort of task.

However, RPM is somewhat braindead in it's file naming. Hyphens are used 
to separate package name and version, but are allowed (and commonly 
used) within package names as well. Cut is as a result somewhat useless, 
as is awk.

However, RPM has a built-in format printing control. Please read the RPM 
documentation, starting with "man rpm". Under the "QUERY OPTIONS" 
section you'll find mention of the "--qf" option to write a custom 
output format for a query. Read "man printf" to find out what format 
escapes you can use.

This document has an example in it that does exactly what you need.

In this case, it comes out as

rpm -qa --qf '%{NAME}\n'

Craig Ringer



More information about the plug mailing list