to write a script to compare the file size in the current directory and previous dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to write a script to compare the file size in the current directory and previous dir
# 1  
Old 02-09-2009
Java 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  
Old 02-09-2009
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  
Old 02-09-2009
Quote:
Originally Posted by tweety
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  
Old 02-09-2009
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  
Old 02-09-2009
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  
Old 02-10-2009
Quote:
Originally Posted by tweety
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare previous and current item in for loop in bash?

Hey, I am trying to compare formated login and logout dates from one user at a host which I have stored in a tmp directory in order to find out the total login time. I need to compare them in order to find overlapping intervals. At first I tried to store each log in and logo date in an array... (3 Replies)
Discussion started by: Mumu123
3 Replies

2. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

3. UNIX for Dummies Questions & Answers

Viewing file size in current directory

What is the command line for viewing the sizes(lines and bytes)of all the files in your present working directory? Is it >ls -la (2 Replies)
Discussion started by: Payton2704
2 Replies

4. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

5. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

6. Shell Programming and Scripting

AWK Compare previous value with current.

Hi, I have one small doubt how to go ahead and process the below requirement. File Content 1,abc,10 2,xyz,11 3,pqr,12 4,pqr,13 5,pqr,14 Output file expected: 1,mnq,1 1,ddd,2 1,qqq,3 1,sss,4 1,ddd,5 1,eee,6 1,fff,7 1,ddr,8 1,rrd,9 (3 Replies)
Discussion started by: dikesm
3 Replies

7. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

8. Shell Programming and Scripting

Find which dir is big size in a directory

Hi all, Could you please tellme the commadn which sorts the list of directories in a parent dir by their size. Thanks. (2 Replies)
Discussion started by: firestar
2 Replies

9. Shell Programming and Scripting

How to compare size of two file which is in one directory

I have two file in a Directory.I want a script which will compare the Size of Two file. Can Anyone Help me on this: linasplg11:/opt/dataout/kk/linasplg11 # cat size -rwxrwxrwx 1 root root 16658 Jan 8 13:58 lina_IP_SIP_1231325621210.xml -rwxr-xr-x 1 root root 16672 Jan 8 14:30... (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

10. Shell Programming and Scripting

Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things: STEP 1) Verify that the file arrived in morning. STEP 2) Compare the file size of the current... (3 Replies)
Discussion started by: rbknisely
3 Replies
Login or Register to Ask a Question