user3341592
user3341592

Reputation: 1561

Shell script to properly align columns

I have a (3-columns) TAB-delimited file, such as:

activity_log    manager Manager
reserve_rm_hreserver_rm_log manager Manager
mo  apprv_mgr1  Approving Manager
wrview  manager Manager

I'd like to get columns correctly aligned; in this case:

activity_log                  manager      Manager
reserve_rm_hreserver_rm_log   manager      Manager
mo                            apprv_mgr1   Approving Manager
wrview                        manager      Manager

No doubt this is doable with awk, by scanning the longest string in every column, and using that for formatting the column printing. I could do that.

But I'm sure there must be a one-liner to do that much more easily. Am I right?

Upvotes: 6

Views: 4127

Answers (1)

mauro
mauro

Reputation: 5940

This should work:

$ column -t myfile.txt

you can use different chars to fill (man column is your friend)

Upvotes: 4

Related Questions