Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active December 10, 2015 13:18
Show Gist options
  • Save nicerobot/4440321 to your computer and use it in GitHub Desktop.
Save nicerobot/4440321 to your computer and use it in GitHub Desktop.
Convert line-oriented output into multi-column output.
#!/bin/bash
columns=${1:-4}
# Tab separated:
${TAB:-false} && awk -v columns=${columns} -v RS='\n' '{ORS=(++i%columns?"\t":"\n");print}END{print "\n"}'
# Fixed width:
${TAB:-false} || awk -v width=${width} -v columns=${columns} -v RS='\n' '{printf "%-*s%s",width,$0,(++i%columns?"":"\n")}END{print "\n"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment