File Count Based on FileDate using Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Count Based on FileDate using Shell Script
# 1  
Old 01-15-2015
File Count Based on FileDate using Shell Script

I have file listed in my directory in following format

Code:
-rwxrwxr-x+ 1 test        test 4.9M Oct  3 16:06 test20141002150108.txt
-rwxrwxr-x+ 1 test        test 4.9M Oct  4 16:06 test20141003150108.txt
-rwxrwxr-x+ 1 test        test 4.9M Oct  5 16:06 test20141005150108.txt
-rwxrwxr-x+ 1 test        test 4.9M Oct  5 16:06 test20141005150108.txt
-rwxrwxr-x+ 1 test        test 4.9M Oct  5 16:06 test20141005150108.txt

I want Output in following format

Code:
DateMoved FileDate Count  Size
  Oct 3   20141002   1         4.9
  Oct 4   20141003   1         4.9
  Oct 5   20141005   3         14.7

Already I am using below script to determine DateMoved,Count and Size.

Code:
printf '\nDATE\tFILES\tSIZE\n'
cd /Mydir
ls -lrt | grep "^-" | awk '
{	nkey = $6$7
	if(key != nkey && key != "") {
		printf("%s\t%d\t%d\n", key, freq, size)
		freq = 1;
		size = $5
	} else {freq++
		size += $5
	}
	key = nkey
}
END {	printf("%s\t%d\t%d\n", key, freq, size)
}'

Help me to get FileDate as well based on the file name.
Appreciate your help.

Thanks
# 2  
Old 01-15-2015
Hello Krish2014,

Could you please try following and let me know if this helps.(Not tested though)
Code:
ls -lrht test2014* | grep "^-" | awk '
	BEGIN{printf("%s\t%s\t%s\t%s\n", "DATE MOVED", "FileDate", "Count", "Size")}
{
	nkey = $6$7
	if(key != nkey && key != "") {
		FileDate=substr($NF,5,8);
		printf("%s\t%s\t%d\t%d\n", key, FileDate, freq, size)
		freq = 1;
		size = $5
	} else {freq++
		size += $5
	}
	key = nkey
}
END {	printf("%s\t%s\t%d\t%d\n", key, FileDate, freq, size)
}'

Thanks,
R. Singh
# 3  
Old 01-15-2015
Hello RavinderSingh13,

I tried to execute above code. But i did not receive FileDate.
Here is the sample output I got

Code:
DATE MOVED      FileDate        Count   Size
Jan15           106     540078423

106=Count
540078423 = Size (Human Readable)

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Run shell script based on date file

Hi Team, I have a to run a script based on a date present in a different file which updates everyday. Kindly help with the solution. My current execution : ksh scriptname.sh 10152019. But here i want to enter this date from a file which gets updated daily. My appraoch : date file location:... (3 Replies)
Discussion started by: midhun3108
3 Replies

2. Shell Programming and Scripting

Linux shell script to insert new lines based on delimiter count

The input file is a .dat file which is delimited by null (^@ in Linux). On a windows PC it looks something like this (numbers are masked with 1). https://i.imgur.com/nta2Gqp.jpg The entire file is in one row but it has multiple records - each record contains 80 fields i.e. there are 81 counts... (9 Replies)
Discussion started by: digitalnirvana
9 Replies

3. Shell Programming and Scripting

Script Shell: Count The sum of numbers in a file

Hi all; Here is my file: V1.3=4 V1.4=5 V1.1=3 V1.2=6 V1.3=6 Please, can you help me to write a script shell that counts the sum of values in my file (4+5+3+6+6) ? Thank you so much for help. Kind regards. (3 Replies)
Discussion started by: chercheur111
3 Replies

4. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

5. Shell Programming and Scripting

Validate file count in korn shell script

Hi, I have files in the directory like below which I need to validate if all the required files are present. A_B_001 of 002_time1.txt A_B_002 of 002_time1.txt A_B_001 of 001_time2.txt Scenarios- a)If file with 001 of 002_time1 or 002 of 002_time1 is missing in the folder,script should... (6 Replies)
Discussion started by: aneeta13
6 Replies

6. Shell Programming and Scripting

Print record count of a file using shell script

HI, I need to print the record count of a file using shell script. If the record count of a file excluding header and trailer record if greater than zero then print 'Record count of a file is xxxx records'. If the record count is zero print 'zero records' Thanks Mahendra (1 Reply)
Discussion started by: mmeda
1 Replies

7. Shell Programming and Scripting

shell script to get the arrival count of file

Hello All, I have come across a small problem. It would be great if any of you could help me in resolving the issue. one file named dummy.txt will be ftped to Unix machine twice daily. If i receive it second time in a day i need to do some processing with the file. How to find the... (2 Replies)
Discussion started by: RSC1985
2 Replies

8. Shell Programming and Scripting

shell script to format file based on specific patterns

Please help me out and drag me out the deadlock I am stuck into: I have a file. I want the statements under a if...then condition be listed in a separate file in the manner condition|statement.Following are the different input pattern and corresponding output parameters.any generic code to... (7 Replies)
Discussion started by: joyan321
7 Replies

9. Shell Programming and Scripting

Shell script to email based on flat file output

Hi All, I am a newbee in unix but still have written a shell script which should trigger a mail based on certain conditions but the problem is that my file is not being read. Below is the code please advise. I do not know where is it failing. Note $ and the no followed with it is the no of... (1 Reply)
Discussion started by: apoorva
1 Replies

10. UNIX for Dummies Questions & Answers

Shell script to return all the ID's from file based on the distribution ID search

Hi, Please help me out on this I have to store some distribution lists(dl) in a file say mail.txt Say the file format be d1 = alok@yahoo.co.in;alvin@rediffmail.com;vijay@yahoo.com; & so on... d2 = abhinav@gmail.com;dalpit@hotmail.com;garima@yahoo.com;& so on... d3 = .... & so on Now what... (1 Reply)
Discussion started by: kumbhatalok
1 Replies
Login or Register to Ask a Question