How can I clean up misaligned columns in text?

前端 未结 6 722
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 09:08

I have a C program that outputs two columns, utterly misaligned. The reason for the misalignment is lengths of words in the first column are very different.

I have an o

6条回答
  •  野性不改
    2021-01-31 09:57

    For a quick-and-dirty fix, pipe it through column:

    your_program | column -t
    

    If you need to include spaces in the column data, then delimit the fields with some character such as "|" and:

    your_program | column -t -s "|"
    

    You can use any character for a delimiter and specify it with the -s switch. Control characters are possible but a little trickier to work with.

    But as Jay mentioned you're better off fixing your program to format the output properly.

提交回复
热议问题