Ubuntu – How to separate fields with space or tab in awk

awkcommand linetext processing

While playing with awk I came to execute:

ls -la >> a.txt ; awk {'print $5  $1'} a.txt ;

This is giving output like:

53277-rw-------
52347-rw-------

How can I get a space between these two friends of output?

Best Answer

Just change the line to

ls -la >> a.txt ; awk {'print $5 "        " $1'} a.txt ;

this should print the output with spaces.

Hope this helps.

Edit:

As suggested by McNisse you can use printf, which would provide you good output format

ls -la >> a.txt ; awk {'printf ("%5s\t%s\n", $5, $1)'} a.txt ;
Related Question