filter file size and file name

I want to filter file information so that i have a column containing file size adjacent to a column containing that files name.

I am using:

find . -type f -exec ls -l {} \; | awk '$5 $9 {print $5 $9}'

and the problem lies with $9 because it prints the file path, /. . ./filename.
I want the filename to print not the file path.

Remove the unwanted strings using awk function sub

find . -type f -exec ls -l {} \; | awk '{sub(/.*\//,"",$9);print $5,$9}'
1 Like
#!/usr/ksh

echo `find . -type f -exec ls -l {} \; | awk '$5 {print $5}'` > file_size
echo `find . -type f -exec basename {} \; | awk '$9 {print $9}'` > file_name

while read -A file_Size
do
        while read -A file_Name
        do
                for #incomplete for loop
                echo ${file_Size} ${file_Name}
                let "i = i + 1"
        done < file_name

done < file_size

---------- Post updated at 02:28 AM ---------- Previous update was at 02:04 AM ----------

#!/usr/ksh

echo `find . -type f -exec ls -l {} \; | awk '$5 {print $5}'` > file_size
echo `find . -type f -exec basename {} \;` > file_name
i=0
while read -A file_Size
do
        while read -A file_Name
        do
                while [ i -lt ${#file_Name[*]} ]
                do
                        echo ${file_Size} ${file_Name} 
                        let "i = i + 1"
                done
        done < file_name
done < file_size

Hi Robin,

Pls try this using sed and awk:

find . -type f -exec ls -1 {} \; | sed 's/\(.*\)\///g' | xargs ls -l | awk '{print $4,$8;}'
find . -type f -exec ls -l {} \; |nawk '{gsub(/.*\//,"",$8);print $4,$8}'

thanks,
Shanmu