shellunixawksolarissolaris-10

Roundup after decimal in awk in solaris os


I want total size of file in a folder using certain file starting with name like abc_1_* in sun solaris os because here i cannot use du -ch, current i am using find command i am getting required output but i want round up output after decimal

Current code :-

echo `find $DUMPDIR -name "${DUMPFILE}*" -exec ls -ltr {} \;  | awk ' {s+=$5} END {print s/1024/1024/1024}'`

output:-

  1.768932

Desired output:-

1.7G

Kindly help me with this i am new to solaris


Solution

  • find $DUMPDIR -name "${DUMPFILE}*" -exec ls -lh {} \; | awk '{print $5}'
    

    You can use GNU extension -h option for ls to print sizes in human readable format. Note: as suggested by @Andrew Henle, -h is not guaranteed to be supported in ls.

    Or simply use,

    ls -lh "$DUMPDIR/${DUMPFILE}*" | cut -d' ' -f 5