If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > get file name.file size,record count using shell script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-20-11, 23:43
qutesanju qutesanju is offline
Registered User
 
Join Date: Sep 2011
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 09-21-11, 09:06
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
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
Reply With Quote
Reply

Tags
file name, record count, size

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On