Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output is disrupted when word has leading or trailing spaces #19

Closed
LukeSavefrogs opened this issue Apr 14, 2023 · 2 comments
Closed

Output is disrupted when word has leading or trailing spaces #19

LukeSavefrogs opened this issue Apr 14, 2023 · 2 comments

Comments

@LukeSavefrogs
Copy link
Owner

...Continuing discussion from my comment on issue #18...

Problem

When any word in the line has a leading or trailing space, all next words get shifted.

Examples

  • Does not work, word be has leading space:
printf "test\tshort\nthis\twont\t be\taligned\nwith\tthe\trest\n" | src/column_ansi.sh -t
test    short   
this    wont         be aligned
with    the     rest
  • Does not work, word this has trailing space:
printf "test\tshort\nthis \twont\tbe\taligned\nwith\tthe\trest\n" | src/column_ansi.sh -t
test    short   
this            wont    be      aligned
with    the     rest
  • Works, no words with leading or trailing spaces:
printf "test\tshort\nthis\twill\tbe\taligned\nwith\tthe\trest\n" | src/column_ansi.sh -t
test    short
this    will    be      aligned
with    the     rest
@LukeSavefrogs
Copy link
Owner Author

LukeSavefrogs commented Dec 2, 2023

Workaround

Specifying the output separator as $"\t" renders the output as it should.

See the differences by yourself:

  • Works, word be has leading space:
printf "test\tshort\nthis\twont\t be\taligned\nwith\tthe\trest\n" | src/column_ansi.sh -t -s $"\t"
test  short
this  wont    be   aligned
with  the    rest
  • Works, word this has trailing space:
printf "test\tshort\nthis \twont\tbe\taligned\nwith\tthe\trest\n" | src/column_ansi.sh -t -s $"\t"
test   short
this   wont   be    aligned
with   the    rest
  • Works, no words with leading or trailing spaces:
printf "test\tshort\nthis\twill\tbe\taligned\nwith\tthe\trest\n" | src/column_ansi.sh -t -s $"\t"
test  short
this  will   be    aligned
with  the    rest

@LukeSavefrogs
Copy link
Owner Author

This issue has been solved by using a regex instead of a plain string matching spaces.. This happened because tabs were kept as is in the output, whereas column interprets both \s and \t as default column separator.

$INPUT_SEPARATOR = qr/[\s\t]+/;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant