bash helpers related to slicing/formatting columns from lines of text
git clone git@github.com:ryan-williams/col-helpers.git
echo "source $PWD/col-helpers/.cols-rc" >> ~/.bashrc
. ~/.bashrc
Write some test data:
cat <<EOF >foo
0 1 2 3 4 5 6
0 1 2 3 4 5 6
00 11 22 33 44 55 66
00,11,22,33,44,55,66
EOF
Get columns from index 2 on:
cat foo | col 2:
# 2 3 4 5 6
# 2 3 4 5 6
# 22 33 44 55 66
#
Get columns [2,4):
cat foo | col 2:4
# 2 3
# 2 3
# 22 33
#
Negative indices work:
cat foo | col -2:
# 5 6
# 5 6
# 55 66
# 00,11,22,33,44,55,66
cat foo | col :-2
# 0 1 2 3 4
# 0 1 2 3 4
# 00 11 22 33 44
#
cat foo | col 2:-2
# 2 3 4
# 2 3 4
# 22 33 44
#
Slice an individual column:
cat foo | col -2
# 5
# 5
# 55
#
Customize input/output delimiters:
cat foo | col -i, -o'|' 2:5
#
#
#
# 22|33|44
Multiple columns/ranges can be separated by commas:
cat foo | col 1,3:-1
# 1 3 4 5
# 1 3 4 5
# 11 33 44 55
#
shorthands for col 0
, col 1
, and col -1
, resp.
echo 1 2 3 4 5 | spc
# 1
# 2
# 3
# 4
# 5
echo 1,2,3,4,5 | sp,
# 1
# 2
# 3
# 4
# 5
See alias definitions in .cols-rc
.
Align columns by a given delimiter.
Write some test data:
cat <<EOF>foo
a,b,c,d,e
AAAAA,BBBBB,CCCCC,DDDDD,EEEEE
111,222,333,444,555
EOF
Format:
ct, foo
# a b c d e
# AAAAA BBBBB CCCCC DDDDD EEEEE
# 111 222 333 444 555
See alias definitions in .cols-rc
.