Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

while I'm playing with awk I came to execute like

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

then its giving output like

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

how can I get space between those two friends of output .

share|improve this question
As an advice, you should not parse the output of ls. This will bite you in the back sooner or later. – gniourf_gniourf Dec 23 '12 at 10:08
In awk, to concatenate two strings, you just place them side-by-side -- print $5 $1 – glenn jackman Dec 23 '12 at 12:31

2 Answers

up vote 6 down vote accepted

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 ;
share|improve this answer
1  
The printf function provides better control, specially if you want to format numbers. printf("%s\t%s\n", $5, $1) – McNisse Dec 23 '12 at 10:11

Another awk-specific technique, use the "output field separator"

ls -la | awk -v OFS='\t' '{print $5, $1}'

The comma is crucial here.

share|improve this answer
thanks for the answer , its also working . – Jai Dec 23 '12 at 13:06

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.