command to layout tab separated list nicely

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












33















Sometimes, I'm getting as an input tab separated list, which is not quite aligned, for instance



var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3


Is there an easy way to render them aligned?



var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3









share|improve this question
























  • Someone could make a solution based on elastic tabstops: nickgravgaard.com/elastictabstops

    – Mikel
    Feb 20 '11 at 9:24











  • See also: vim.org/scripts/script.php?script_id=294 and vimcasts.org/episodes/aligning-text-with-tabular-vim

    – Mikel
    Feb 20 '11 at 9:29











  • And a Go implementation: golang.org/pkg/tabwriter

    – Mikel
    Feb 20 '11 at 10:00






  • 15





    Tried piping it to column -t?

    – alex
    Feb 20 '11 at 11:45






  • 7





    Tucked away at the end of Mikel's perl answer is the clincher comment (by Mikel)... columns -t acts on general whitespace. To work with tabs only, use column -t -s $'t'

    – Peter.O
    Feb 20 '11 at 23:40















33















Sometimes, I'm getting as an input tab separated list, which is not quite aligned, for instance



var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3


Is there an easy way to render them aligned?



var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3









share|improve this question
























  • Someone could make a solution based on elastic tabstops: nickgravgaard.com/elastictabstops

    – Mikel
    Feb 20 '11 at 9:24











  • See also: vim.org/scripts/script.php?script_id=294 and vimcasts.org/episodes/aligning-text-with-tabular-vim

    – Mikel
    Feb 20 '11 at 9:29











  • And a Go implementation: golang.org/pkg/tabwriter

    – Mikel
    Feb 20 '11 at 10:00






  • 15





    Tried piping it to column -t?

    – alex
    Feb 20 '11 at 11:45






  • 7





    Tucked away at the end of Mikel's perl answer is the clincher comment (by Mikel)... columns -t acts on general whitespace. To work with tabs only, use column -t -s $'t'

    – Peter.O
    Feb 20 '11 at 23:40













33












33








33


12






Sometimes, I'm getting as an input tab separated list, which is not quite aligned, for instance



var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3


Is there an easy way to render them aligned?



var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3









share|improve this question
















Sometimes, I'm getting as an input tab separated list, which is not quite aligned, for instance



var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3


Is there an easy way to render them aligned?



var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3






command-line text-processing csv tabulation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 20 '11 at 19:14









Gilles

535k12810811599




535k12810811599










asked Feb 20 '11 at 8:45









Elazar LeibovichElazar Leibovich

1,27131621




1,27131621












  • Someone could make a solution based on elastic tabstops: nickgravgaard.com/elastictabstops

    – Mikel
    Feb 20 '11 at 9:24











  • See also: vim.org/scripts/script.php?script_id=294 and vimcasts.org/episodes/aligning-text-with-tabular-vim

    – Mikel
    Feb 20 '11 at 9:29











  • And a Go implementation: golang.org/pkg/tabwriter

    – Mikel
    Feb 20 '11 at 10:00






  • 15





    Tried piping it to column -t?

    – alex
    Feb 20 '11 at 11:45






  • 7





    Tucked away at the end of Mikel's perl answer is the clincher comment (by Mikel)... columns -t acts on general whitespace. To work with tabs only, use column -t -s $'t'

    – Peter.O
    Feb 20 '11 at 23:40

















  • Someone could make a solution based on elastic tabstops: nickgravgaard.com/elastictabstops

    – Mikel
    Feb 20 '11 at 9:24











  • See also: vim.org/scripts/script.php?script_id=294 and vimcasts.org/episodes/aligning-text-with-tabular-vim

    – Mikel
    Feb 20 '11 at 9:29











  • And a Go implementation: golang.org/pkg/tabwriter

    – Mikel
    Feb 20 '11 at 10:00






  • 15





    Tried piping it to column -t?

    – alex
    Feb 20 '11 at 11:45






  • 7





    Tucked away at the end of Mikel's perl answer is the clincher comment (by Mikel)... columns -t acts on general whitespace. To work with tabs only, use column -t -s $'t'

    – Peter.O
    Feb 20 '11 at 23:40
















Someone could make a solution based on elastic tabstops: nickgravgaard.com/elastictabstops

– Mikel
Feb 20 '11 at 9:24





Someone could make a solution based on elastic tabstops: nickgravgaard.com/elastictabstops

– Mikel
Feb 20 '11 at 9:24













See also: vim.org/scripts/script.php?script_id=294 and vimcasts.org/episodes/aligning-text-with-tabular-vim

– Mikel
Feb 20 '11 at 9:29





See also: vim.org/scripts/script.php?script_id=294 and vimcasts.org/episodes/aligning-text-with-tabular-vim

– Mikel
Feb 20 '11 at 9:29













And a Go implementation: golang.org/pkg/tabwriter

– Mikel
Feb 20 '11 at 10:00





And a Go implementation: golang.org/pkg/tabwriter

– Mikel
Feb 20 '11 at 10:00




15




15





Tried piping it to column -t?

– alex
Feb 20 '11 at 11:45





Tried piping it to column -t?

– alex
Feb 20 '11 at 11:45




7




7





Tucked away at the end of Mikel's perl answer is the clincher comment (by Mikel)... columns -t acts on general whitespace. To work with tabs only, use column -t -s $'t'

– Peter.O
Feb 20 '11 at 23:40





Tucked away at the end of Mikel's perl answer is the clincher comment (by Mikel)... columns -t acts on general whitespace. To work with tabs only, use column -t -s $'t'

– Peter.O
Feb 20 '11 at 23:40










6 Answers
6






active

oldest

votes


















46














So, the answer becomes:



column -t file_name


Note that this splits columns at any whitespace, not just tabs. If you want to split on tabs only, use:



column -t -s $'t' -n file_name


The -s $'t' sets the delimiter to tabs only and -n preserves empty columns (adjacent tabs).



P.S.: Just want to point out that the credit goes to Alex as well. The original hint was provided by him as a comment to the question, but was never posted as an answer.






share|improve this answer

























  • I'll wait a bit for Alex to get the credit, I think he deserves it. If he wouldn't answer in a few days I'll accept an answer from somebody else.

    – Elazar Leibovich
    Feb 20 '11 at 19:23











  • Sure! I too was unaware of column :)

    – Barun
    Feb 21 '11 at 5:51






  • 1





    This seems ideal but unfortunately column seems to fail when it encounters empty cells. See this post. Depending on which version of column you have, you may be able to specify the -n option to correct this.

    – John J. Camilleri
    Jul 18 '12 at 7:29












  • Also, this command will not only split on tabs, but also on "any whitespace". To split just on tabs, use column -t -s $'t'.

    – Fritz
    Feb 6 '17 at 12:45


















3














Here's a script to do it:



aligntabs.pl



#!/usr/bin/perl

my $delim = 's*ts*';

my %length = ();
my @lines = ();
for my $line (<>)
chomp $line;
my @words = split $delim, $line;
my $numwords = scalar(@words);
for my $i (0..$numwords-1)
my $maxlen = $length$i // 0;
my $thislen = length($words[$i]);
$maxlen = ($thislen > $maxlen)? $thislen: $maxlen;
$length$i = $maxlen;

push @lines, [@words];


foreach my $wordsref (@lines)
my @words = @$wordsref;
my $numwords = scalar(@words);
for my $i (0..$numwords-1)
if ($i < $numwords-1)
my $fieldlen = $length$i;
printf "%-$fieldlens ", $words[$i];

else
print $words[$i];


print "n";



usage



$ aligntabs.pl < infile
var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3





share|improve this answer























  • Um, thanks, but I was hoping there's a more "portable" way to do that.

    – Elazar Leibovich
    Feb 20 '11 at 11:08











  • Me too! Couldn't find one. pr and nl are the two basic tools for the formatting, and after that awk, sed, perl, etc.

    – Mikel
    Feb 20 '11 at 11:13






  • 1





    it's as simple as column

    – Elazar Leibovich
    Feb 20 '11 at 11:51






  • 2





    @Elzar Excellent! column -t -s $'t' seems to do the job.

    – Mikel
    Feb 20 '11 at 20:33


















3














For manual tab stops: expand -t 42,48



For automatic tab stops, as suggested by alex: column -t



(expand is on all POSIX systems. column is a BSD utility, available in many Linux distributions as well.)






share|improve this answer
































    1














    Following on from Peter.O's comment which is what I wanted to align (tab delimited data, TSV), this phrase works very nicely:



    column -t -s $'t' /Users/me/data.csv | less --chop-long-lines





    share|improve this answer






























      0














      sed 's/||/| |/g;s/||/| |/g' filename-here | column -s"|" -t | less -#2 -N -S


      Explanation:



      Sed will add a space between blank delimters



      Column will add equal spacing between the columns



      zydsld|asl|asd
      das|aosdk|dd


      becomes



      zydsld|asl |asd
      das |aosdk|dd


      Less will open the output in a file viewer. -N and -S will add line number and disable wrapping respectively






      share|improve this answer




















      • 1





        One-line answers are often not the most helpful. Consider expanding your post to include explanation of your solution, or documentation that supports it.

        – HalosGhost
        Aug 6 '14 at 17:57


















      0














      With Miller (http://johnkerl.org/miller/doc) you have pretty print output.



      Run



      mlr --inidx --ifs "t" --opprint cat input | tail -n +2


      to have



      var1 var2 var3
      var_with_long_name_which_ruins_alignment var2 var3





      share|improve this answer






















        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f7698%2fcommand-to-layout-tab-separated-list-nicely%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        46














        So, the answer becomes:



        column -t file_name


        Note that this splits columns at any whitespace, not just tabs. If you want to split on tabs only, use:



        column -t -s $'t' -n file_name


        The -s $'t' sets the delimiter to tabs only and -n preserves empty columns (adjacent tabs).



        P.S.: Just want to point out that the credit goes to Alex as well. The original hint was provided by him as a comment to the question, but was never posted as an answer.






        share|improve this answer

























        • I'll wait a bit for Alex to get the credit, I think he deserves it. If he wouldn't answer in a few days I'll accept an answer from somebody else.

          – Elazar Leibovich
          Feb 20 '11 at 19:23











        • Sure! I too was unaware of column :)

          – Barun
          Feb 21 '11 at 5:51






        • 1





          This seems ideal but unfortunately column seems to fail when it encounters empty cells. See this post. Depending on which version of column you have, you may be able to specify the -n option to correct this.

          – John J. Camilleri
          Jul 18 '12 at 7:29












        • Also, this command will not only split on tabs, but also on "any whitespace". To split just on tabs, use column -t -s $'t'.

          – Fritz
          Feb 6 '17 at 12:45















        46














        So, the answer becomes:



        column -t file_name


        Note that this splits columns at any whitespace, not just tabs. If you want to split on tabs only, use:



        column -t -s $'t' -n file_name


        The -s $'t' sets the delimiter to tabs only and -n preserves empty columns (adjacent tabs).



        P.S.: Just want to point out that the credit goes to Alex as well. The original hint was provided by him as a comment to the question, but was never posted as an answer.






        share|improve this answer

























        • I'll wait a bit for Alex to get the credit, I think he deserves it. If he wouldn't answer in a few days I'll accept an answer from somebody else.

          – Elazar Leibovich
          Feb 20 '11 at 19:23











        • Sure! I too was unaware of column :)

          – Barun
          Feb 21 '11 at 5:51






        • 1





          This seems ideal but unfortunately column seems to fail when it encounters empty cells. See this post. Depending on which version of column you have, you may be able to specify the -n option to correct this.

          – John J. Camilleri
          Jul 18 '12 at 7:29












        • Also, this command will not only split on tabs, but also on "any whitespace". To split just on tabs, use column -t -s $'t'.

          – Fritz
          Feb 6 '17 at 12:45













        46












        46








        46







        So, the answer becomes:



        column -t file_name


        Note that this splits columns at any whitespace, not just tabs. If you want to split on tabs only, use:



        column -t -s $'t' -n file_name


        The -s $'t' sets the delimiter to tabs only and -n preserves empty columns (adjacent tabs).



        P.S.: Just want to point out that the credit goes to Alex as well. The original hint was provided by him as a comment to the question, but was never posted as an answer.






        share|improve this answer















        So, the answer becomes:



        column -t file_name


        Note that this splits columns at any whitespace, not just tabs. If you want to split on tabs only, use:



        column -t -s $'t' -n file_name


        The -s $'t' sets the delimiter to tabs only and -n preserves empty columns (adjacent tabs).



        P.S.: Just want to point out that the credit goes to Alex as well. The original hint was provided by him as a comment to the question, but was never posted as an answer.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 13 '17 at 12:36









        Community

        1




        1










        answered Feb 20 '11 at 17:19









        BarunBarun

        2,0071522




        2,0071522












        • I'll wait a bit for Alex to get the credit, I think he deserves it. If he wouldn't answer in a few days I'll accept an answer from somebody else.

          – Elazar Leibovich
          Feb 20 '11 at 19:23











        • Sure! I too was unaware of column :)

          – Barun
          Feb 21 '11 at 5:51






        • 1





          This seems ideal but unfortunately column seems to fail when it encounters empty cells. See this post. Depending on which version of column you have, you may be able to specify the -n option to correct this.

          – John J. Camilleri
          Jul 18 '12 at 7:29












        • Also, this command will not only split on tabs, but also on "any whitespace". To split just on tabs, use column -t -s $'t'.

          – Fritz
          Feb 6 '17 at 12:45

















        • I'll wait a bit for Alex to get the credit, I think he deserves it. If he wouldn't answer in a few days I'll accept an answer from somebody else.

          – Elazar Leibovich
          Feb 20 '11 at 19:23











        • Sure! I too was unaware of column :)

          – Barun
          Feb 21 '11 at 5:51






        • 1





          This seems ideal but unfortunately column seems to fail when it encounters empty cells. See this post. Depending on which version of column you have, you may be able to specify the -n option to correct this.

          – John J. Camilleri
          Jul 18 '12 at 7:29












        • Also, this command will not only split on tabs, but also on "any whitespace". To split just on tabs, use column -t -s $'t'.

          – Fritz
          Feb 6 '17 at 12:45
















        I'll wait a bit for Alex to get the credit, I think he deserves it. If he wouldn't answer in a few days I'll accept an answer from somebody else.

        – Elazar Leibovich
        Feb 20 '11 at 19:23





        I'll wait a bit for Alex to get the credit, I think he deserves it. If he wouldn't answer in a few days I'll accept an answer from somebody else.

        – Elazar Leibovich
        Feb 20 '11 at 19:23













        Sure! I too was unaware of column :)

        – Barun
        Feb 21 '11 at 5:51





        Sure! I too was unaware of column :)

        – Barun
        Feb 21 '11 at 5:51




        1




        1





        This seems ideal but unfortunately column seems to fail when it encounters empty cells. See this post. Depending on which version of column you have, you may be able to specify the -n option to correct this.

        – John J. Camilleri
        Jul 18 '12 at 7:29






        This seems ideal but unfortunately column seems to fail when it encounters empty cells. See this post. Depending on which version of column you have, you may be able to specify the -n option to correct this.

        – John J. Camilleri
        Jul 18 '12 at 7:29














        Also, this command will not only split on tabs, but also on "any whitespace". To split just on tabs, use column -t -s $'t'.

        – Fritz
        Feb 6 '17 at 12:45





        Also, this command will not only split on tabs, but also on "any whitespace". To split just on tabs, use column -t -s $'t'.

        – Fritz
        Feb 6 '17 at 12:45













        3














        Here's a script to do it:



        aligntabs.pl



        #!/usr/bin/perl

        my $delim = 's*ts*';

        my %length = ();
        my @lines = ();
        for my $line (<>)
        chomp $line;
        my @words = split $delim, $line;
        my $numwords = scalar(@words);
        for my $i (0..$numwords-1)
        my $maxlen = $length$i // 0;
        my $thislen = length($words[$i]);
        $maxlen = ($thislen > $maxlen)? $thislen: $maxlen;
        $length$i = $maxlen;

        push @lines, [@words];


        foreach my $wordsref (@lines)
        my @words = @$wordsref;
        my $numwords = scalar(@words);
        for my $i (0..$numwords-1)
        if ($i < $numwords-1)
        my $fieldlen = $length$i;
        printf "%-$fieldlens ", $words[$i];

        else
        print $words[$i];


        print "n";



        usage



        $ aligntabs.pl < infile
        var1 var2 var3
        var_with_long_name_which_ruins_alignment var2 var3





        share|improve this answer























        • Um, thanks, but I was hoping there's a more "portable" way to do that.

          – Elazar Leibovich
          Feb 20 '11 at 11:08











        • Me too! Couldn't find one. pr and nl are the two basic tools for the formatting, and after that awk, sed, perl, etc.

          – Mikel
          Feb 20 '11 at 11:13






        • 1





          it's as simple as column

          – Elazar Leibovich
          Feb 20 '11 at 11:51






        • 2





          @Elzar Excellent! column -t -s $'t' seems to do the job.

          – Mikel
          Feb 20 '11 at 20:33















        3














        Here's a script to do it:



        aligntabs.pl



        #!/usr/bin/perl

        my $delim = 's*ts*';

        my %length = ();
        my @lines = ();
        for my $line (<>)
        chomp $line;
        my @words = split $delim, $line;
        my $numwords = scalar(@words);
        for my $i (0..$numwords-1)
        my $maxlen = $length$i // 0;
        my $thislen = length($words[$i]);
        $maxlen = ($thislen > $maxlen)? $thislen: $maxlen;
        $length$i = $maxlen;

        push @lines, [@words];


        foreach my $wordsref (@lines)
        my @words = @$wordsref;
        my $numwords = scalar(@words);
        for my $i (0..$numwords-1)
        if ($i < $numwords-1)
        my $fieldlen = $length$i;
        printf "%-$fieldlens ", $words[$i];

        else
        print $words[$i];


        print "n";



        usage



        $ aligntabs.pl < infile
        var1 var2 var3
        var_with_long_name_which_ruins_alignment var2 var3





        share|improve this answer























        • Um, thanks, but I was hoping there's a more "portable" way to do that.

          – Elazar Leibovich
          Feb 20 '11 at 11:08











        • Me too! Couldn't find one. pr and nl are the two basic tools for the formatting, and after that awk, sed, perl, etc.

          – Mikel
          Feb 20 '11 at 11:13






        • 1





          it's as simple as column

          – Elazar Leibovich
          Feb 20 '11 at 11:51






        • 2





          @Elzar Excellent! column -t -s $'t' seems to do the job.

          – Mikel
          Feb 20 '11 at 20:33













        3












        3








        3







        Here's a script to do it:



        aligntabs.pl



        #!/usr/bin/perl

        my $delim = 's*ts*';

        my %length = ();
        my @lines = ();
        for my $line (<>)
        chomp $line;
        my @words = split $delim, $line;
        my $numwords = scalar(@words);
        for my $i (0..$numwords-1)
        my $maxlen = $length$i // 0;
        my $thislen = length($words[$i]);
        $maxlen = ($thislen > $maxlen)? $thislen: $maxlen;
        $length$i = $maxlen;

        push @lines, [@words];


        foreach my $wordsref (@lines)
        my @words = @$wordsref;
        my $numwords = scalar(@words);
        for my $i (0..$numwords-1)
        if ($i < $numwords-1)
        my $fieldlen = $length$i;
        printf "%-$fieldlens ", $words[$i];

        else
        print $words[$i];


        print "n";



        usage



        $ aligntabs.pl < infile
        var1 var2 var3
        var_with_long_name_which_ruins_alignment var2 var3





        share|improve this answer













        Here's a script to do it:



        aligntabs.pl



        #!/usr/bin/perl

        my $delim = 's*ts*';

        my %length = ();
        my @lines = ();
        for my $line (<>)
        chomp $line;
        my @words = split $delim, $line;
        my $numwords = scalar(@words);
        for my $i (0..$numwords-1)
        my $maxlen = $length$i // 0;
        my $thislen = length($words[$i]);
        $maxlen = ($thislen > $maxlen)? $thislen: $maxlen;
        $length$i = $maxlen;

        push @lines, [@words];


        foreach my $wordsref (@lines)
        my @words = @$wordsref;
        my $numwords = scalar(@words);
        for my $i (0..$numwords-1)
        if ($i < $numwords-1)
        my $fieldlen = $length$i;
        printf "%-$fieldlens ", $words[$i];

        else
        print $words[$i];


        print "n";



        usage



        $ aligntabs.pl < infile
        var1 var2 var3
        var_with_long_name_which_ruins_alignment var2 var3






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 20 '11 at 9:57









        MikelMikel

        39.4k1099125




        39.4k1099125












        • Um, thanks, but I was hoping there's a more "portable" way to do that.

          – Elazar Leibovich
          Feb 20 '11 at 11:08











        • Me too! Couldn't find one. pr and nl are the two basic tools for the formatting, and after that awk, sed, perl, etc.

          – Mikel
          Feb 20 '11 at 11:13






        • 1





          it's as simple as column

          – Elazar Leibovich
          Feb 20 '11 at 11:51






        • 2





          @Elzar Excellent! column -t -s $'t' seems to do the job.

          – Mikel
          Feb 20 '11 at 20:33

















        • Um, thanks, but I was hoping there's a more "portable" way to do that.

          – Elazar Leibovich
          Feb 20 '11 at 11:08











        • Me too! Couldn't find one. pr and nl are the two basic tools for the formatting, and after that awk, sed, perl, etc.

          – Mikel
          Feb 20 '11 at 11:13






        • 1





          it's as simple as column

          – Elazar Leibovich
          Feb 20 '11 at 11:51






        • 2





          @Elzar Excellent! column -t -s $'t' seems to do the job.

          – Mikel
          Feb 20 '11 at 20:33
















        Um, thanks, but I was hoping there's a more "portable" way to do that.

        – Elazar Leibovich
        Feb 20 '11 at 11:08





        Um, thanks, but I was hoping there's a more "portable" way to do that.

        – Elazar Leibovich
        Feb 20 '11 at 11:08













        Me too! Couldn't find one. pr and nl are the two basic tools for the formatting, and after that awk, sed, perl, etc.

        – Mikel
        Feb 20 '11 at 11:13





        Me too! Couldn't find one. pr and nl are the two basic tools for the formatting, and after that awk, sed, perl, etc.

        – Mikel
        Feb 20 '11 at 11:13




        1




        1





        it's as simple as column

        – Elazar Leibovich
        Feb 20 '11 at 11:51





        it's as simple as column

        – Elazar Leibovich
        Feb 20 '11 at 11:51




        2




        2





        @Elzar Excellent! column -t -s $'t' seems to do the job.

        – Mikel
        Feb 20 '11 at 20:33





        @Elzar Excellent! column -t -s $'t' seems to do the job.

        – Mikel
        Feb 20 '11 at 20:33











        3














        For manual tab stops: expand -t 42,48



        For automatic tab stops, as suggested by alex: column -t



        (expand is on all POSIX systems. column is a BSD utility, available in many Linux distributions as well.)






        share|improve this answer





























          3














          For manual tab stops: expand -t 42,48



          For automatic tab stops, as suggested by alex: column -t



          (expand is on all POSIX systems. column is a BSD utility, available in many Linux distributions as well.)






          share|improve this answer



























            3












            3








            3







            For manual tab stops: expand -t 42,48



            For automatic tab stops, as suggested by alex: column -t



            (expand is on all POSIX systems. column is a BSD utility, available in many Linux distributions as well.)






            share|improve this answer















            For manual tab stops: expand -t 42,48



            For automatic tab stops, as suggested by alex: column -t



            (expand is on all POSIX systems. column is a BSD utility, available in many Linux distributions as well.)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 13 '17 at 12:36









            Community

            1




            1










            answered Feb 20 '11 at 19:18









            GillesGilles

            535k12810811599




            535k12810811599





















                1














                Following on from Peter.O's comment which is what I wanted to align (tab delimited data, TSV), this phrase works very nicely:



                column -t -s $'t' /Users/me/data.csv | less --chop-long-lines





                share|improve this answer



























                  1














                  Following on from Peter.O's comment which is what I wanted to align (tab delimited data, TSV), this phrase works very nicely:



                  column -t -s $'t' /Users/me/data.csv | less --chop-long-lines





                  share|improve this answer

























                    1












                    1








                    1







                    Following on from Peter.O's comment which is what I wanted to align (tab delimited data, TSV), this phrase works very nicely:



                    column -t -s $'t' /Users/me/data.csv | less --chop-long-lines





                    share|improve this answer













                    Following on from Peter.O's comment which is what I wanted to align (tab delimited data, TSV), this phrase works very nicely:



                    column -t -s $'t' /Users/me/data.csv | less --chop-long-lines






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 21 '16 at 19:51









                    user7000user7000

                    597521




                    597521





















                        0














                        sed 's/||/| |/g;s/||/| |/g' filename-here | column -s"|" -t | less -#2 -N -S


                        Explanation:



                        Sed will add a space between blank delimters



                        Column will add equal spacing between the columns



                        zydsld|asl|asd
                        das|aosdk|dd


                        becomes



                        zydsld|asl |asd
                        das |aosdk|dd


                        Less will open the output in a file viewer. -N and -S will add line number and disable wrapping respectively






                        share|improve this answer




















                        • 1





                          One-line answers are often not the most helpful. Consider expanding your post to include explanation of your solution, or documentation that supports it.

                          – HalosGhost
                          Aug 6 '14 at 17:57















                        0














                        sed 's/||/| |/g;s/||/| |/g' filename-here | column -s"|" -t | less -#2 -N -S


                        Explanation:



                        Sed will add a space between blank delimters



                        Column will add equal spacing between the columns



                        zydsld|asl|asd
                        das|aosdk|dd


                        becomes



                        zydsld|asl |asd
                        das |aosdk|dd


                        Less will open the output in a file viewer. -N and -S will add line number and disable wrapping respectively






                        share|improve this answer




















                        • 1





                          One-line answers are often not the most helpful. Consider expanding your post to include explanation of your solution, or documentation that supports it.

                          – HalosGhost
                          Aug 6 '14 at 17:57













                        0












                        0








                        0







                        sed 's/||/| |/g;s/||/| |/g' filename-here | column -s"|" -t | less -#2 -N -S


                        Explanation:



                        Sed will add a space between blank delimters



                        Column will add equal spacing between the columns



                        zydsld|asl|asd
                        das|aosdk|dd


                        becomes



                        zydsld|asl |asd
                        das |aosdk|dd


                        Less will open the output in a file viewer. -N and -S will add line number and disable wrapping respectively






                        share|improve this answer















                        sed 's/||/| |/g;s/||/| |/g' filename-here | column -s"|" -t | less -#2 -N -S


                        Explanation:



                        Sed will add a space between blank delimters



                        Column will add equal spacing between the columns



                        zydsld|asl|asd
                        das|aosdk|dd


                        becomes



                        zydsld|asl |asd
                        das |aosdk|dd


                        Less will open the output in a file viewer. -N and -S will add line number and disable wrapping respectively







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Aug 20 '14 at 18:10

























                        answered Aug 6 '14 at 17:34









                        RohitRohit

                        11




                        11







                        • 1





                          One-line answers are often not the most helpful. Consider expanding your post to include explanation of your solution, or documentation that supports it.

                          – HalosGhost
                          Aug 6 '14 at 17:57












                        • 1





                          One-line answers are often not the most helpful. Consider expanding your post to include explanation of your solution, or documentation that supports it.

                          – HalosGhost
                          Aug 6 '14 at 17:57







                        1




                        1





                        One-line answers are often not the most helpful. Consider expanding your post to include explanation of your solution, or documentation that supports it.

                        – HalosGhost
                        Aug 6 '14 at 17:57





                        One-line answers are often not the most helpful. Consider expanding your post to include explanation of your solution, or documentation that supports it.

                        – HalosGhost
                        Aug 6 '14 at 17:57











                        0














                        With Miller (http://johnkerl.org/miller/doc) you have pretty print output.



                        Run



                        mlr --inidx --ifs "t" --opprint cat input | tail -n +2


                        to have



                        var1 var2 var3
                        var_with_long_name_which_ruins_alignment var2 var3





                        share|improve this answer



























                          0














                          With Miller (http://johnkerl.org/miller/doc) you have pretty print output.



                          Run



                          mlr --inidx --ifs "t" --opprint cat input | tail -n +2


                          to have



                          var1 var2 var3
                          var_with_long_name_which_ruins_alignment var2 var3





                          share|improve this answer

























                            0












                            0








                            0







                            With Miller (http://johnkerl.org/miller/doc) you have pretty print output.



                            Run



                            mlr --inidx --ifs "t" --opprint cat input | tail -n +2


                            to have



                            var1 var2 var3
                            var_with_long_name_which_ruins_alignment var2 var3





                            share|improve this answer













                            With Miller (http://johnkerl.org/miller/doc) you have pretty print output.



                            Run



                            mlr --inidx --ifs "t" --opprint cat input | tail -n +2


                            to have



                            var1 var2 var3
                            var_with_long_name_which_ruins_alignment var2 var3






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 19 at 7:30









                            aborrusoaborruso

                            21829




                            21829



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f7698%2fcommand-to-layout-tab-separated-list-nicely%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown






                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay