I've read this thread https://unix.stackexchange.com/a/7718/256195, that only if var doesn't contain any tab/spaces but in my case it does contain spaces, like below example:

"this is a test"      this_is_a_solid_line_that_doesnot_contain_tab_or_spaces

command column will separate this is ..etc also, but I'd want something acts on only "this is a test" and this_is_a_solid_line_that_doesnot_contain_tab_or_spaces.

Purpose: I have a bunch of lines like above in a file that don't be aligned properly.

closed as unclear what you're asking by Kusalananda, Thomas, schily, Stephen Kitt, Jesse_b Nov 29 '18 at 16:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Are the fields tab-delimited? – Kusalananda Nov 29 '18 at 7:55
  • Possibly of some help (if the fields are tab-delimited): Align columns evenly without "column - t" – Kusalananda Nov 29 '18 at 7:56
  • Thanks, what would it be when I'm using pipeline like: cat file | somethine_here_to_filter, what would your script will be put after a pipeline? – Tuyen Pham Nov 29 '18 at 8:00
  • The shell script in the second half of my answer expects a filename, so ./script.sh file. To make it work on a pipe, use something-that-produces-data | ./script.sh /dev/stdin. – Kusalananda Nov 29 '18 at 8:05
  • @Kusalananda: I tried but with var1 test it produces "var1.................................................................test" that somehow treat spaces as tab. – Tuyen Pham Nov 29 '18 at 8:32

Assuming the input doesn't contain | characters, you could convert those sequences of whitespace that are not inside quotes to | (or any other character that doesn't occur in the input) and then pipe to column -ts'|':

<input.txt perl -lpe 's/(".*?")|\s+/$1||"|"/ge' | column -ts'|'
  • This is golden. I've just tested against this and achieved the question in simple and elegant way. – Tuyen Pham Nov 29 '18 at 8:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.