Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
works flawlessly, thanks! :) –  nifr Jun 9 '13 at 12:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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