command to layout tab separated list nicely
Clash Royale CLAN TAG#URR8PPP
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
|
show 1 more comment
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
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 tocolumn -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, usecolumn -t -s $'t'
– Peter.O
Feb 20 '11 at 23:40
|
show 1 more comment
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
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
command-line text-processing csv tabulation
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 tocolumn -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, usecolumn -t -s $'t'
– Peter.O
Feb 20 '11 at 23:40
|
show 1 more comment
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 tocolumn -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, usecolumn -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
|
show 1 more comment
6 Answers
6
active
oldest
votes
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.
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 ofcolumn
:)
– Barun
Feb 21 '11 at 5:51
1
This seems ideal but unfortunatelycolumn
seems to fail when it encounters empty cells. See this post. Depending on which version ofcolumn
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, usecolumn -t -s $'t'
.
– Fritz
Feb 6 '17 at 12:45
add a comment |
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
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
andnl
are the two basic tools for the formatting, and after thatawk
,sed
,perl
, etc.
– Mikel
Feb 20 '11 at 11:13
1
it's as simple ascolumn
– 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
add a comment |
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.)
add a comment |
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
add a comment |
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
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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 ofcolumn
:)
– Barun
Feb 21 '11 at 5:51
1
This seems ideal but unfortunatelycolumn
seems to fail when it encounters empty cells. See this post. Depending on which version ofcolumn
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, usecolumn -t -s $'t'
.
– Fritz
Feb 6 '17 at 12:45
add a comment |
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.
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 ofcolumn
:)
– Barun
Feb 21 '11 at 5:51
1
This seems ideal but unfortunatelycolumn
seems to fail when it encounters empty cells. See this post. Depending on which version ofcolumn
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, usecolumn -t -s $'t'
.
– Fritz
Feb 6 '17 at 12:45
add a comment |
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.
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.
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 ofcolumn
:)
– Barun
Feb 21 '11 at 5:51
1
This seems ideal but unfortunatelycolumn
seems to fail when it encounters empty cells. See this post. Depending on which version ofcolumn
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, usecolumn -t -s $'t'
.
– Fritz
Feb 6 '17 at 12:45
add a comment |
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 ofcolumn
:)
– Barun
Feb 21 '11 at 5:51
1
This seems ideal but unfortunatelycolumn
seems to fail when it encounters empty cells. See this post. Depending on which version ofcolumn
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, usecolumn -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
add a comment |
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
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
andnl
are the two basic tools for the formatting, and after thatawk
,sed
,perl
, etc.
– Mikel
Feb 20 '11 at 11:13
1
it's as simple ascolumn
– 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
add a comment |
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
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
andnl
are the two basic tools for the formatting, and after thatawk
,sed
,perl
, etc.
– Mikel
Feb 20 '11 at 11:13
1
it's as simple ascolumn
– 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
add a comment |
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
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
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
andnl
are the two basic tools for the formatting, and after thatawk
,sed
,perl
, etc.
– Mikel
Feb 20 '11 at 11:13
1
it's as simple ascolumn
– 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
add a comment |
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
andnl
are the two basic tools for the formatting, and after thatawk
,sed
,perl
, etc.
– Mikel
Feb 20 '11 at 11:13
1
it's as simple ascolumn
– 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
add a comment |
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.)
add a comment |
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.)
add a comment |
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.)
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.)
edited Apr 13 '17 at 12:36
Community♦
1
1
answered Feb 20 '11 at 19:18
GillesGilles
535k12810811599
535k12810811599
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Jul 21 '16 at 19:51
user7000user7000
597521
597521
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Jan 19 at 7:30
aborrusoaborruso
21829
21829
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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, usecolumn -t -s $'t'
– Peter.O
Feb 20 '11 at 23:40