relidon
relidon

Reputation: 2292

How to split a string into columns in bash

I am making an alias function where it returns some comments which remind me of what alias I need to run for different functionality, this is as example :

echo 'sendToDropBox "localFile", "remoteDir"  # send a local file to dropbox ' 
echo 'evernote "title", "conte/file", "notebook_name"  # send to evernote, notebook_name is optional'

I want the content starting from # to align. I searched columns, but they only seem to work with data coming from a file. I tried this :

printf "%s\n" "this is a test" | column -t

But that just spaces the words. How can I get this output

ToDropBox "localFile", "remoteDir"               # send a local file to dropbox
evernote "title", "conte/file", "notebook_name"  # send to evernote...
tweet "book", "tweet"                            # post a tweet...

Upvotes: 0

Views: 286

Answers (1)

SLePort
SLePort

Reputation: 15461

You can use printf formatting :

printf "%-35s %s\n" "line1" "# comment" "line2" "# other comment"

%-35s reserve 35 characters when displaying first variable (- for left align).

Upvotes: 1

Related Questions