~adigitoleo/reshape

Reshape delimited text files

a7c9bb6 feat: Support '\s' syntax for space delimiter

4 months ago

8af7320 docs: Update README todo list

6 months ago

#reshape

Reshape delimited text files.

Reads input from a file if the filename is given as the last argument. Reads from stdin stream (e.g. unix pipe) otherwise, until terminated by an EOF signal. A filename argument of - can also be used to switch to stdin input. Note that the whole input is read into memory at once for processing.

#Examples

Transpose:

printf 'a,b,c'|reshape -d, -t
a
b
c

Reshape:

printf '%s\n%s\n' 'a,b,c' '1,2,3'|reshape -d, -s3x2
a,b
c,1
2,3

Output is right-aligned by default (use -p or --nopad to disable):

printf '%s\n%s\n%s\n' 'a,b,c' '1,2,3' 'foo,bar,baz'|reshape -d,
  a,  b,  c
  1,  2,  3
foo,bar,baz

Skip individual rows/columns or ranges:

printf '%s\n%s\n%s\n' 'a,b,c' '1,2,3' 'foo,bar,baz'|reshape -d, -r:1 -c:1-2
  3
baz

Note that unicode symbols are currently not aligned properly:

printf '%s\n%s\n%s\n' ',a,b,c,d' ',1,2,3,4' ',",",,ß'|reshape -d, -c1 -s3x4
  a,b, c,d
  1,2, 3,4
",", ,ß,

#Install

After building the reshape binary, put it in one of your $PATH directories.

#Build

Release build: nim c -d:release src/reshape.nim

Debug build: nim c src/reshape.nim

#Test

Run nimble test in the source code root directory.

Linux CI (dev branch): builds.sr.ht status

#Use

Run with the --help option if built, or check the printHelp proc in the code. Note that short options must not be separated from their arguments by a space. Use : or = instead, or append the argument to the option flag directly. This behaviour is inherited from Nim's parseopt module.

#Similar solutions

#TODO

  • Fix cell padding for tables with unicode characters.