How do I right justify columns in a file

awk, justify, sed

Solution

In lieu of a specific example here is a general solution using a trick with `rev`:

$ cat file
a 10000.00 x
b 100 y
c 1 zzzZZ

$ rev file | column -t | rev
a  10000.00      x
b       100      y
c         1  zzzZZ

Where `column -t` is replaced by whatever you are trying to do.

Problem

How do I right justify the columns of a file in awk, sed, or bash ? My file is currently left justified and space delimited. Can I used `printf` or `rev`? Here is what my file looks like : ``` $ cat file 14,107 aaa 12,436 0.0 0 0 313 0 373 3,806,201 bbb 1,573 0.0 0 0 -25 0 -25 ``` And using `rev` doesn't give me the output I'm looking for. ``` $rev file | column -t | rev 14,107 aaa 12,436 0.0 0 0 313 0 373 3,806,201 bbb 1,573 0.0 0 0 -25 0 -25 ```

Original source

Related problems