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?
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?
Just change the line to
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
Another awk-specific technique, use the "output field separator"
The comma is crucial here.
A simple way to get tabs is:
I know this is an old thread, but I'm just learning and found these posts helpful. My best solution was to use gawk to insert spaces between the variables for you.
To place the space between the arguments, just add
" "
, e.g.awk {'print $5" "$1'}
.However it is not recommended to parse output of
ls
command, since it's not reliable and output is for humans, not scripts. Therefore use alternative commands such asfind
orstat
.Here is example using GNU
stat
:which will print you machine-friendly output (in terse form), so you can get exactly what you need. Then use
-c
to use specific format, or useawk
,cut
orread
to get the right columns.Check
stat --help
for further options. For example to print day of modification, check this example.