Is there an easy way to split comma-delimited lines of text into columns with some of the columns right-justified?As a bonus, it would be nice to format numbers, but this probably isn't too hard with sed.
Split a line into columns with some of the columns right-justified?
text processing;table
Awk and the %42s printf format comes to mind. Here's a simple script to get you started. Setting width[i] to a positive value in the BEGIN clause makes that column have the given width, left-aligned. If width[i] is negative, then column i is right-aligned and has the width -width[i]. This script doesn't handle wide fields intelligently, all subsequent columns are just shifted right on that line.awk -F, -vOFS= 'BEGIN {width[1]=-10; width[2]=8;}{ for (i=1; i<=NF; i++) {$i = sprintf(%*s, width[i], $i)}  print }'If you have numeric fields, you can use other printf formats.If you have the BSD utility column (Debian ships it, I don't know about other Linux distributions), you can easily format things in columns with column -t -s ,. The nice thing about column is that it determines the column width automatically. However, it doesn't do right-hand formatting; while you can get it with some post-processing, I don't know if the complexity is worth it.You could do everything in Perl. Its format facility may help.A more powerful approach to table formatting with common unix tools is tbl, which is the part of *roff (the man page formatter) that handles tables. But that's also more complex because you need to convert the input to roff.Yet another possible tool is the text mode browser w3m, which is good at table rendering. Here, you'd have to convert the input to HTML.