Command-line interface

Passing items

When running from the command-line there are two ways to feed the shcol command with items: You can either give it a sequence of arguments representing the items (e.g. shcol foo bar baz) or you pass the items through its standard input stream.

The latter form makes it easy to combine shcol with other shell commands. On Windows PowerShell, for example, you could columnize the names of all running processes starting with “w” like this:

PS C:\> (ps w*).name | shcol
wininit  winlogon  winpty-agent  wlanext  wmpnetwk  WUDFHost

Configuring the output

By default, shcol will put 2 space characters between the items. Also, it is able to detect the terminal’s line width automatically in most cases in order to use that width for columnizing. But of course, you can change the spacing as well as the line width to be used.

To change the spacing just use the -s (long form: --spacing) option. If you want the columnized output of the previously shown example to include 5 space characters then you would do this:

PS C:\> (ps w*).name | shcol -s5
wininit     winlogon     winpty-agent     wlanext     wmpnetwk     WUDFHost

Or more verbosely:

PS C:\> (ps w*).name | shcol --spacing=5
wininit     winlogon     winpty-agent     wlanext     wmpnetwk     WUDFHost

For changing the line width you make use of the -w (long form: --width) option. This shows an example for a line width of 50 characters:

PS C:\> (ps w*).name | shcol -w50
wininit   winpty-agent  wmpnetwk
winlogon  wlanext       WUDFHost
PS C:\> (ps w*).name | shcol --width=50
wininit   winpty-agent  wmpnetwk
winlogon  wlanext       WUDFHost

Using an extra separator

If you need to add an additional separator between the columns then this can be done by using the -e (long form: --extra-sep) option:

PS C:\> (ps w*).name | shcol -e"-"
wininit - winlogon - winpty-agent - WUDFHost
PS C:\> (ps w*).name | shcol --extra-sep="-"
wininit - winlogon - winpty-agent - WUDFHost
PS C:\> (ps w*).name | shcol --extra-sep="-" --width=25
wininit  - winpty-agent
winlogon - WUDFHost

(New feature in development version - not yet released.)

Selecting a specific column

If your input consists of lines that represent multiple columns then you probably want to choose a specific column to be processed by shcol. To achieve this you can use the -c (long form: --column) option.

shcol interprets a column as a sequence of non-whitespace characters. Column counting starts with 0 like indices do in most programming languages.

The following snippet shows how to use this option:

PS C:\> echo foo`tXXX bar`tYYY baz`tZZZ
foo     XXX
bar     YYY
baz     ZZZ
PS C:\> echo foo`tXXX bar`tYYY baz`tZZZ | shcol -c0
foo  bar  baz
PS C:\> echo foo`tXXX bar`tYYY baz`tZZZ | shcol --column=1
XXX  YYY  ZZZ

Using patterns

Sometimes you want to filter your input according to specific criteria. For this, shcol supports filtering by wildcards (namely: ? and *). You make use of filtering by passing a pattern to the -F (long form: --filter) option.

Filtering can be done like this:

PS C:\> echo foo bar baz | shcol -F"f*"
foo
PS C:\> echo foo bar baz | shcol -F"b*"
bar  baz
PS C:\> echo foo bar baz | shcol -F"*a*"
bar  baz
PS C:\> echo foo bar baz | shcol -F"*r"
bar
PS C:\> echo foo bar baz | shcol -F"ba?"
bar  baz
PS C:\> echo foo bar baz | shcol --filter="?a?"
bar  baz

Sorting the items

shcol is able to sort the given items before columnizing them. This sorting will be locale-dependent on most systems. It is based on the system’s default locale settings. To enable sorting you use the -S (long form: --sort) option.

The following example shows sorting including an item with a German Umlaut and with German set as the default locale:

PS C:\> shcol foo bär baz -S
bär  baz  foo
PS C:\> shcol foo bär baz --sort
bär  baz  foo

Making items unique

If your input contains duplicates and you don’t want to have duplicates in your columnized output then the -U (long form: --unique) option is a good way to deal with that.

If this option is enabled then shcol will ignore subsequent occurrences of an item that already has been processed.

The effect when using that option is illustrated by the following example:

PS C:\> shcol foo bar foo baz bar baz foo -U
foo  bar  baz
PS C:\> shcol foo bar foo baz bar baz foo --unique
foo  bar  baz