miller icon indicating copy to clipboard operation
miller copied to clipboard

PPRINT with multi-character FS

Open agguser opened this issue 6 months ago • 0 comments

Currently, if OFS is multiple characters, PPRINT does not align well; e.g.

$ <<. mlr --c2p --ofs='  ' cat   # note two-space FS
a,b
1 11,2 22
.
a         b   # note b is not left-aligned with below
1 11   2 22

I think that is because of using OFS to align (use --ofs=XY and see the result) instead of just spaces. So please change this (or add a flag e.g. --no-repofs), so that the above output would be

a     b
1 11  2 22

The beautifully aligned result can be used as-is as input, e.g.

$ <<. mlr --p2c --ifs='  ' cat
a     b
1 11  2 22
.
a, b      # note a space
1 11,2 22

But note the leading space before “b” in the output, this could be fixed with using clean-whitespace instead of cat. But it would be better if spaces (padding characters of PPRINT) surrounding IFS would be automatically removed (or if a new flag, e.g. --no-repifs, is specified) (e.g. using a PERL regexp *$OFS(?:(?!.*$OFS) *)? to split).

Also, --no-repifs with a non-all-space IFS would allow empty fields in PPRINT without encoded as -, e.g.

$ <<. mlr --p2c --ifs=' | ' --no-repifs cat
a    | x | b
1 11 |   | 2 22
.
a,x,b
1 11,,2 22

agguser avatar Jun 21 '25 03:06 agguser