Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<b>How do I comapre file sizes?<b>

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
Hello, I would like to to do a file compare, this compare will give me the byte count and if there is a difference, I would like the output to tell me what file byte difference is from both files. I have a static file that will be used to do a comparison with, within this file is a list of file names, but I am not sure how I can get a byte count unless I create a different file with that information(byte) on it. Okay, enough of the blah, blah, does anybody know how I can add to the script below and compare the byte count of each file that is in a static file to the files on a system?

Here is the script I would like to add to.

I hope I am making sense. Thanks to all of you.

#!/bin/ksh

SERVER=`uname -n`
DIR=/REGO

FILELIST=/DJ/PUB/testrego
for xx in `cat $FILELIST`
do
if [ ! -f $xx ]
then
print "File Missing:$DIR$xx- On Machine:${SERVER}"
fi
done < ${FILELIST}
 
For your static file:

NAME_OF_FILE:BYTE_SIZE

For your script:

#!/usr/bin/ksh -p

for i in `cat ${FILELIST}`
do
V1=`echo ${i}|/usr/bin/cut -d &quot;:&quot; -f1`
V2=`echo ${i}|/usr/bin/cut -d &quot;:&quot; -f2`
V3=`/usr/bin/ls -l ${DIR}/${i}|/usr/bin/awk '{print $5}'`

if [ ! -f ${V1} ]
then
print &quot;File Missing:....&quot;
fi

if [ ${V2} -ne ${V3} ]
then
print &quot;File: ${i} has a mismatched byte count, last known count: ${V2}, current count: ${V3}.....please correct!!!&quot;
fi
done


As for you static TOC for the directory, use:

ls -l | awk '{print $9 &quot;:&quot; $5}' > YOUR_TOC_FILE_NAME
 
Thank you pmcmicha for your help. Can you please help with some terms.

I am not sure what you mean by:

For your static file:

NAME_OF_FILE:BYTE_SIZE <--I am sure what you mean by this->

Also, do I use ls -l | awk '{print $9 &quot;:&quot; $5}' > YOUR_TOC_FILE_NAME to create my Static File for bite size differentiation?

What do you mean by TOC?

I don't mean to bug you with this, but sometimes I get lost in the lingo.

Thank you so much for your help.
 
Static File:

NAME_OF_FILE:BYTE_SIZE

testfile:6

So if you had a file by the name of testfile and it was 6 bytes, then it would show up in your static TOC (Table of Contents) file. The first field: testfile is you file name, the &quot;:&quot; is the standerd seperater in this paticular TOC, and the second field: 6 was the current byte size of that paticular file when you made the TOC.


Yes, use the command you asked about to create your TOC. Name the TOC whatever you want it to be, in your original post it was: /DJ/PUB/testrego which was the variable: FILELIST.


Does this answer your questions?
 
You are too good, and I do thank you so much. And I do understand.

Could I use this one TOC file for multiple directories? If I had 13 directories that I wanted to check byte sizes on, would I repeat the ls -l with the | to awk command 13 times with a >> to append to the one file? If so, how do I compare byte counts with different directories in one file?

Thank you pmcmicha
 
If you need to span multiple directories use this to create the TOC:

ls -l `pwd`/*|awk '{print $9 &quot;:&quot; $5}' >> SOME_DIR/YOUR_TOC

Once for each directory.

V3=`/usr/bin/ls -l ${V1}|awk '{print $5}'`

You remove the ${DIR} since ${V1} would already have your full path to the file. # Mistake in original post.


That should get your TOC in working order.
 
This is not working for some reason. I am not sure what I am doing wrong. The script looks like its executing but for some reason it just hangs. Here is what I have.

Remember that I am new to this, so all your help will be appreciated.

#!/bin/ksh -p

TOCLIST:41609 <I get this error: TOCLIST:41609: not found>

for i in `cat ${TOCLIST}`
do
V1=`echo ${i}|/bin/cut -d &quot;:&quot; -f1`
V2=`echo ${i}|/bin/cut -d &quot;:&quot; -f2`
V3=`/bin/ls -l ${V1}|awk '{print $5}'`
if [ ! -f ${V1} ]
then
print &quot;File Missing:....&quot;
fi

if [ ${V2} -ne ${V3} ]
then
print &quot;File: ${i} has a mismatched byte count, last known count:
${V2}, current count: ${V3}.....please correct!!!&quot;
fi
done
 
Its me again, this is the error I am getting after I tweaked the script can someone please help?

Script:

#!/bin/ksh -p

TOCLIST=/DJ/PUB/TOCLIST
echo &quot;1&quot;
for i in `cat ${TOCLIST}`
do
V1=`echo ${i}|/bin/cut -d &quot;:&quot; -f1`
V2=`echo ${i}|/bin/cut -d &quot;:&quot; -f2`
V3=`/bin/ls -l ${V1}|awk '{print $5}'`

if [ ! -f ${V1} ]
then
print &quot;File Missing:....&quot;
fi

if [ ${V2} -ne ${V3} ]
then
print &quot;File: ${i} has a mismatched byte count, last known count:
${V2}, current count: ${V3}.....please correct!!!&quot;
fi
done



Error I am getting:

shell/iX> ./count
1
ls: File or directory &quot;TESTC&quot; is not found
File Missing:....
./count 20: [: expression syntax error
ls: File or directory &quot;TESTCK&quot; is not found
File Missing:....
./count 20: [: expression syntax error
./count 20: [: expression syntax error
./count 20: [: expression syntax error
./count 20: [: expression syntax error
ls: File or directory &quot;DOC&quot; is not found
File Missing:....
./count 20: [: expression syntax error
ls: File or directory &quot;LIBDOC&quot; is not found
File Missing:....
./count 20: [: expression syntax error
ls: File or directory &quot;LIBRARY&quot; is not found
File Missing:....
./count 20: [: expression syntax error
ls: File or directory &quot;PREFS&quot; is not found
File Missing:....
./count 20: [: expression syntax error

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top