I am running

rpm -Vqf 

to check if various system files are correct. The below is a sample output.

S.5....T.  c /etc/enviro
missing     /var/run/abrt
file /etc/bluetooth is not owned by any package

I would like the output to be like the below in order to see the full path to the file. If permisions /ownr/checksum... are correct, if it is missing or not owned by a package.

/etc/bluetooth|not owned

I was looking at awk but can't quit get it correct.


Assuming that your output is always as presented for the three examples you provided, the following should work:

rpm -Vqf <arguments> | awk '/(\/[^/ ]+)+$/ {printf("%s|%s\n",$NF,$1);next} /is not owned/{printf("%s|not owned\n",$2)}'

This call to awk does the following:

  • If a line ends with an absolute file path (i.e. a / followed by any number of "non-slashes" (that are also no spaces), and that pattern possibly repeated), use printf to print the last record (= whitespace-separated string), which is the filepath, followed by the |, and then the first record. Then, skip execution to the next input line (otherwise you might get multiple output for the same input line).
  • If a line contains the string "is not owned", print the second record (which is the file path assuming that the output always reads file <name> is not owned ...), followed by the fixed string "not owned".
  • Thank you very much however on the file <name is not owned i seem to get package | file not sure why but thank you so much – heathc Jan 20 '20 at 13:12
  • See edited text, there was a typo (missing "space" after / in the square brackets) XD – AdminBee Jan 20 '20 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.