Skip to content

Instantly share code, notes, and snippets.

@jagipson
Last active December 15, 2015 13:59
Show Gist options
  • Save jagipson/5271632 to your computer and use it in GitHub Desktop.
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.
#!/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) }
@jagipson
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment