Alice
Alice

Reputation: 37

How to align text by Linux command prompt?

I have a text file and then I want to align it. I used column -t myfile > newfile. But this command delete an empty line which separated two sentences. How can I do now? Please help me.

Myfile: a c                Used column -t : a   c      Desired file: a    c
        bd e                                bd  e                    bd   e
        .                                   .                        .
                                            f   g                     
        f g                                 hi  j                    f    g
        hi j                                                         hi   j

Upvotes: 2

Views: 4342

Answers (1)

Tony
Tony

Reputation: 1657

column -e -t myfile > newfile.

-e is the option for 'Do not ignore empty lines'.

If the -e option is not available -- it appears to be patched in by Debian and derivatives, so may not be available on other systems -- a kludge is:

sed -e 's/^$/###xxx###/' myfile | column -t | sed -e 's/###xxx###//'

where ###xxx### is a string you would not expect to see anywhere in your file. Blank lines are filled by sed with this string before they hit the column command, which stops them being silently dropped. Following the column command, the odd string is removed by sed.

Upvotes: 2

Related Questions