The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to compare size of two file which is in one directory Aditya.Gurgaon Shell Programming and Scripting 1 01-08-2009 06:28 AM
write the script to get the file size and sends an email s_linux Shell Programming and Scripting 10 08-13-2008 11:54 PM
Check File Exists and compare to previous day file script rbknisely Shell Programming and Scripting 3 02-07-2008 11:53 AM
compare file size from a output file from a script moustik Shell Programming and Scripting 7 11-07-2007 10:17 AM
How to write current Date dynamically in a file Sree_2503 Shell Programming and Scripting 5 10-17-2006 05:19 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-09-2009
tweety tweety is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 4
Post to write a script to compare the file size in the current directory and previous dir

hi,

i am new to this site.

i want to write a script to compare the file size of the files in the current dir with the files in the previous directory.

the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to compare the monthly files). so can anybody help me to find a solution for this.

Any help would be greatly appreciated!
  #2 (permalink)  
Old 02-09-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,909
Code:
#!/bin/sh

FILE="xyzddddyymm.txt"

SIZES=( $(stat "--printf=\t%s" "${FILE}" "../${FILE}") )

if [[ "${SIZES[0]}" -gt "${SIZES[1]}" ]]
then
        echo "${FILE} > ../${FILE} by $((SIZES[0]-SIZES[1])) bytes"
elif [[ "${SIZES[1]}" -gt "${SIZES[0]}" ]]
then
        echo "../${FILE} > ${FILE} by $((SIZES[1]-SIZES[0])) bytes"
else
        echo "${FILE} and ../${FILE} are the same size"
fi
  #3 (permalink)  
Old 02-09-2009
tweety tweety is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 4
Quote:
Originally Posted by tweety View Post
hi,

i am new to this site.

i want to write a script to compare the file size of the files in the current dir with the files in the previous directory.

the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to compare the monthly files). so can anybody help me to find a solution for this.

Any help would be greatly appreciated!
Hi Thanks much for your response.

i need one more help.

But i am having 4 files in the current directory and 4 files in the previous dir.

the file names will be same in both the dir, but with different dates. How can i compare all the files in this situation.

can you please help me in this?
  #4 (permalink)  
Old 02-09-2009
ddreggors ddreggors is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 91
try diff:

Code:
[user@host ~]$ diff ./dirA ./dirB
or if you want to test file by file:

Code:
[user@host ~]$ for F in ./dirA/*; do diff ./dirA/${F} ./dirB/${F}; done
  #5 (permalink)  
Old 02-09-2009
tweety tweety is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 4
hi,

the file names will be same in both the dir, but with different dates. How can i compare the file size of all the files in tis.

can you please help me in this?
  #6 (permalink)  
Old 02-10-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,909
Quote:
Originally Posted by tweety View Post
hi,

the file names will be same in both the dir, but with different dates. How can i compare the file size of all the files in tis.

can you please help me in this?
Repeat the above examples four times, with different dates? If that's not it, then a clearer explanation may be needed.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0