Filter RPM URLs with awk
Luke Hebert
- 2 minutes read - 223 wordsWhen you are digging through a long log file or a package manifest and only need the RPM download URLs, a single awk command saves you from scrolling, copying, and pasting. The trick is to match lines that contain both a keyword (like autoinstall) and the .rpm extension, then print just the last field, which is typically the URL or file path.
The Command
awk '/autoinstall/ && /\.rpm/ {print $NF}'How It Works
/autoinstall/matches any line containing the stringautoinstall.&&requires both patterns to be true on the same line./\.rpm/matches any line containing the literal string.rpm(the backslash escapes the dot so it is not treated as a regex wildcard).{print $NF}prints the last whitespace-delimited field on the matching line, which is usually the URL or file path.
Example
Given a log line like:
2022-01-24 10:32:01 INFO autoinstall package http://mirror.example.com/repo/epel/x86_64/epel-release-8-11.el8.noarch.rpmThe command outputs:
http://mirror.example.com/repo/epel/x86_64/epel-release-8-11.el8.noarch.rpmTips
- Swap
autoinstallfor whatever keyword identifies the lines you care about. - If your URLs are not always the last field, replace
$NFwith the specific field number (e.g.,$5). - Pipe the output to
xargsorcurlto download the packages in one step:
awk '/autoinstall/ && /\.rpm/ {print $NF}' install.log | xargs -n1 curl -OThis keeps your terminal clean and your package list accurate without manual copy-paste.