How to render two columns preserving all whitespace after the first column with awk or alternative?

1

my output comes in human-readable figures with one space followed by directory names:

I am currently using ...

awk '{ printf "%-20s %-40s\n", $1, $2 }'

input

1G foo
1.5M foo baz 
5K foo spaces in this directory

output

1G    foo
1.5M  foo 
5K    foo 

desired

1G    foo
1.5M  foo baz 
5K    foo spaces in this directory

How to split into two columns with whitespace delimiter preserving all whitespace in the second column using awk or alternative?

Nicolai Fröhlich

Posted 2013-06-09T07:12:13.517

Reputation: 239

Answers

1

Try this:

$ awk '{ printf "%-20s ", $1; $1=""; print $0 }' input 
1G                    foo
1.5M                  foo baz
5K                    foo spaces in this directory

Resetting the leading columns to an empty string is the usual trick to print all the remaining fields/columns.

Mat

Posted 2013-06-09T07:12:13.517

Reputation: 6 193