Help in finding & comparing avg file size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in finding & comparing avg file size
# 1  
Old 06-12-2013
Help in finding & comparing avg file size

I have some files in a directory with two different extensions which get created everyday. Can you please help me out in getting the average file size for both these extensions and checking it with the last two file sizes of the same file extension ?

To be more clear..
Lets say I have 10 files of which 5 are with .log and other 5 with .txt extensions.
I need to find average size of all .log files and compare it with the latest created .log file size and report if its size is less Smilie

Many thanks in advance

---------- Post updated at 02:13 AM ---------- Previous update was at 01:21 AM ----------

I tried to build up a script and came up with the following snippet:

Code:
AFS= $(ls -l *.log| awk '{sum += $5; n++;} END {sum/n;}')
FS=$(ls -ltr *.log| tail -1 | awk '{print$5}')
for file in $(ls -rt  *.log | tail -1)
do
    if [ ! -s $file ]
    then
echo "$file size is 0"
elif [[ "$FS" -lt "$AFS" ]]
then
echo "$file size is less than average"
fi
done

When I run it, it returns empty.
Code:
elif [[ "$FS" -lt "$AFS" ]]

wondering if this the correct way to compare two values ?
# 2  
Old 06-12-2013
This needs to be corrected
wrong
AFS= $(ls -l *.log| awk '{sum += $5; n++;} END {sum/n;}')
correct
AFS=$(ls -l *.log|awk '{sum+=$5; n++} END {print sum/n}')
Remove space around =
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding size of files with spaces in their file names

I am running a UNIX script to get unused files and their sizes from the server. The issue is arising due to the spaces present in the filename/folder names.Due to this the du -k command doesn't work properly.But I need to calculate the size of all files including the ones which have spaces in them.... (4 Replies)
Discussion started by: INNSAV1
4 Replies

2. Shell Programming and Scripting

Comparing 2 text files & downloading a file if the last lines are different

Hello I'm having a little difficulty in writing a shell script for a few simple tasks. First I have two files "file1.txt" and "file2.txt" and I want to read and compare the last line of each file. The files look like this. File1.txt File2.txt After comparing the two lines I would... (2 Replies)
Discussion started by: RustikGaming
2 Replies

3. Shell Programming and Scripting

Optimised way for search & replace a value on one line in a very huge file (File Size is 24 GB).

Hi Experts, I had to edit (a particular value) in header line of a very huge file so for that i wanted to search & replace a particular value on a file which was of 24 GB in Size. I managed to do it but it took long time to complete. Can anyone please tell me how can we do it in a optimised... (7 Replies)
Discussion started by: manishkomar007
7 Replies

4. Shell Programming and Scripting

Finding a file and comparing

Hey all! So this is my problem: when a txtfile is processed, its moved to a directory called YYMMDDHHMMSSSS. Example: /Processed/090624005217 And I want to check that the file ends up in that folder. One of my problems is that I dont know the exact name of that folder.. Then i want to... (2 Replies)
Discussion started by: rrahmegni
2 Replies

5. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

6. Shell Programming and Scripting

help with finding & replacing pattern in a file

Hi everyone. Could u be so kind and help me with on "simple" shell script? 1. i need to search a file line by line for a pattern. example of a lines in that file 2947 domain = feD,id = 00 0A 02 48 17 1E 1D 39 DE 00 0E 00,Name Values:snNo = f10 Add AttFlag = 0 2. i need to find... (0 Replies)
Discussion started by: dusoo
0 Replies

7. UNIX for Dummies Questions & Answers

Help finding/adding up file size...

Ok, I am new to UNIX and Shell scripting and I am trying to do the following using a korn shell script: I have a large data file that is loaded into a database, this data file is split into parts to make it more manageable based on a size parameter. The file contains many account records, the... (1 Reply)
Discussion started by: Stove13
1 Replies

8. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

9. Shell Programming and Scripting

Finding EOL char is there or not in a big size file

Hi, I am using ksh. I have to find wether data file has EOL or not. as per my knowledge we can easily find by checking each character. But this is a tedious job as per my requirement because my data file size is very big . It may be in 25-30 MB. So please advice me how i can check wether... (4 Replies)
Discussion started by: HariRaju
4 Replies

10. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question