Last active
December 15, 2015 13:59
-
-
Save jagipson/5271632 to your computer and use it in GitHub Desktop.
Unmuttles (regularififies) yum list output (or anything that wrongly splits columns over multiple rows.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/awk | |
# usage: yum list | ./fix_yum_list.awk | |
function reform(l) { | |
match(l, /^([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]].*$)/, f) | |
return f[1] "\t" f[2] "\t" f[3] | |
} | |
/^Installed Packages$/ { disp="installed"; next } | |
/^Available Packages$/ { disp="available"; next } | |
(length (buff) > 0) && /^[^[:space:]]/ { print (reform(buff) "\t" disp) } | |
(length (disp) > 0) && /^[^[:space:]]/ { buff = $0; } | |
(length (buff) > 0) && /^[[:space:]]/ { buff = buff $0; } | |
END { print (reform(buff) "\t" disp) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yum list produces columnar output assuming an 80-char width, and if text is too long in a previous column, there's a linefeed, and and indent to the vertical position of the next column. The problem is that a newline should be a record separator. This awk script glues the broken lines together and converts the column separator to the TAB character.