In the command ls -la | awk '{print $5}' the command ouput for size is left to right I need it to be right to left
How do you mean? The fifth field is the size field... I don't get the bit about left to right and right to left...
ls -la | awk '{len = length($5) > len ? length($5) : len ; arr[NR] = $5 }END{ for ( a = 1; a < NR; a++ ) { printf "%"len"s\n" , arr[a]}}'
I mean it printing the correct way with all the numbers lining up the way there supposed to. Test it you'll see what I mean.
That was awsome Reborg it worked perfect.
If I may ask will you please explain it to me.
Chris
Well that worked perfect until I put it into my app
What I am actually trying to do is
for f in $(<uploads); do
s=`echo "$PWD/$f" | sed -e 's/^.*chris\.fileburst\.com/chris.fileburst.com/'`
z=`ls -la "$f" | awk '{len = length($5) > len ? length($5) : len ; arr[NR] = $5 }END{ for ( a = 1; a < NR; a++ ) { printf "%"len"s\n" , arr[a]}}'`
x=`ls -la "$f"| awk '{print $6,$7,$8}'`
y=`md5sum "$f"| awk '{print $1}'`
echo -e "$s\t$z\t$x\t$y"
Now I know thats a long string and it was working with z=ls -la "$f" |awk '{print $5}' It just didn't print the size formatted left to right
Is there a way to incorporate what you gave me into that.
If anyone has any ideas I still really need help with this output. All the ideas I have had only works partially.
I don't have time to explain this code right now, but will post again later, I may be able to correct mistakes, but that depends on time.
#! /bin/awk -f
#
# lineup.awk
#
BEGIN{
maxf = 0
}
{
sub ("^.*chris.fileburst.com", "chris.fileburst.com", $NF)
# may need to adjust to the correct ouput for your system
# keep values sequential
arr[NR,1] = $11
arr[NR,2] = $7
arr[NR,3] = $8
arr[NR,4] = $9
arr[NR,5] = $10
arr[NR,6] = $1
# make sure you keep the i < value one greater that the
# number of entries in the array, same in the END block
for ( i=1 ; i < 7; i++ ) {
if ( length(arr[NR, i]) > maxl ) maxl = length(arr[NR, i])
}
}
END{
for(x=1;x<=NR;x++){
for(y=1;y<7;y++){
if ( i == 2 ) {
printf("%"maxl[y]"s ", arr[x,y])
}
else {
printf("%-"maxl[y]"s ", arr[x,y])
}
}
printf("\n")
}
}
The script becomes:
#!/bin/bash
while read file; do
do echo $(md5sum $file) $(ls -l $PWD/$file)
done < uploads | ./lineup.awk