Question

I'm trying to use column -t -s $'\t' in tcsh (which works in bash) but I can't find a way to make it work

echo "selected version\tnew version\nbbb\tccc\n" | column -t -s $'\t'
Illegal variable name

So what's the equivalent in tcsh?

Was it helpful?

Solution

tcsh doesn't have a mechanism for including non-printing characters in string literals, other than including them directly.

In bash, you can do this (changing echo to printf because its behavior is more consistent):

$ printf "selected version\tnew version\nbbb\tccc\n" | column -t -s $'\t'
selected version  new version
bbb               ccc

In tcsh, you can replace the $'\t' with a literal tab character, entered by typing Ctrl-VTab -- but when you read the code it's indistinguishable from a sequence of spaces.

Here's one solution, using the printf command to convert \t to a tab character:

% printf "selected version\tnew version\nbbb\tccc\n" | column -t -s "`printf '\t'`"
selected version  new version
bbb               ccc

You can also store the tab character in a variable; you can use either double quotes or the :t suffix to retain the literal value when you use it:

% set tab = "`printf '\t'`"
% printf "selected version\tnew version\nbbb\tccc\n" | column -t -s "$tab"
selected version  new version
bbb               ccc
% printf "selected version\tnew version\nbbb\tccc\n" | column -t -s $tab:q
selected version  new version
bbb               ccc

OTHER TIPS

in general, you just ust "\t" for a tab. However, column seems to intepret this literally as a backslash and a letter t. To get around this, you can explicitly enter a tab character by pressing cntl-v and then tab (surrounded by quotes).

Note however, in the case of your specific example, you do not need the -s argument at all, since column separates by whitespace by default.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top