Ok, the problem here is with finding out the file/directory stuff. That's why I used
find in the first place -- because it's
printf feature has the
'%y' option. Since it seems to be GNU only extension, we'll have to find a different way of solving this. We can use the first letter of the file permissions entry in the output of
ls -l. So we'll have
d for directories and
- for files. Let's start with
AWK:
Code:
ls -l|awk '{ print $9"|0|0|"$9 substr($1,0,1) }'
This assumes that the filename is the column
$9 in the output of
ls. (On some systems, it may be
$8, though). It will also break if the filenames contain spaces because the names will be broken into multiple columns. We can do slightly better if we remove all columns from the first one up to
$8 and print the entire line:
Code:
ls -l|awk '{ x=substr($1,0,1); for(i=1;i<9;i++){$i=""}; match ($0,"^ *"); $0=substr($0,RLENGTH+1); print $0"|0|0|"$0x}'
this can hardly be considered a neat one-liner, though. A slightly shorter alternative would be to print all columns from
$9 on in a loop:
Code:
ls -l|awk -F' +' '{ x=$9; for(i=10;i<=NF;i++){x=x" "$i}; print x"|0|0|"x substr($0,0,1)}'
This will, however, break, if the filenames contain multiple consequent spaces, because we assumed that columns are separated by single spaces, which is not neccesarily the case.
Alternatively, here is a somewhat ugly, but shorter
sed version:
Code:
ls -l | sed -e 's/^\(.\)\(\S* *\)\{8\}\(.*\)/\3|0|0|\3\1/'