Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2011
    Posts
    1

    Unanswered: get file name.file size,record count using shell script

    I need to get file name file size rcord count from the specified directory e.g OUTFILES/archive

    at present i tried like this ...
    test.sh
    v_Dir=$1
    echo "the directory to cd to is "$1

    if [ $# -ne 1 ]
    then "echo you must pass in the directory"

    else
    cd $v_Dir
    for x in `ls -lt |grep -v ^d|awk '{print $9}'`
    do

    x=`ls -l $0 | awk '{print $9 "|" $5}'`
    y=`awk 'END {print NR}' $0`
    echo $x '|' $y
    done
    fi

    and its execution would be
    test.sh OUTFILES/archive > testb.log 2>&1

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    The grep statement should be
    Code:
    grep -v "^d"
    When I ran your code, I had problems with the awk statements because the directory was changed.
    So...simplified.
    Code:
    ls -l $1|grep -v "^d"|while read a b c d size f g h name
    do                                                      
       echo $name $size                                        
    done

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •