How to listout the files based on group by the date...?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to listout the files based on group by the date...?
# 1  
Old 04-18-2008
How to listout the files based on group by the date...?

Hi,

How to listout the files based on group by of date...?

suppose if have list of 10 files which was created by on today(Apr 18) and yesterday(Apr 17 ) in my personal directory like this

if i issue ls -rtl | grep "Apr 18" list out the file which was created/updated only on Apr 18th.

Actual files listing
=============

-rwxrwxrwx 1 geae users 278 Apr 17 06:07 sendmail.ksh
-rw-rw-r-- 1 geae users 15 Apr 17 06:26 P.txt
-rw-rw-r-- 1 geae users 375 Apr 17 07:12 simple.ksh
-rwxrwxrwx 1 geae users 375 Apr 17 10:04 dates.ksh
-rwxrwxrwx 1 geae users 555 Apr 18 01:12 IN.txt
-rwxrwxrwx 1 geae users 400 Apr 18 01:13 date_convert.ksh
-rw-rw-r-- 1 geae users 562 Apr 18 01:13 Updt_IN.txt
-rw-rw-r-- 1 geae users 590 Apr 18 02:43 Dir_File.txt
-rwxrwxrwx 1 geae users 1667 Apr 18 02:45 noofdir.ksh
-rw-rw-r-- 1 geae users 301 Apr 18 03:00 date.txt


Now i want to list out the based on the date and count the no of files basded on the date like this

Expected list of output
=================
[UDate: Apr 17 => No of Files:4[/U]
-rwxrwxrwx 1 geae users 278 Apr 17 06:07 sendmail.ksh
-rw-rw-r-- 1 geae users 15 Apr 17 06:26 P.txt
-rw-rw-r-- 1 geae users 375 Apr 17 07:12 simple.ksh
-rwxrwxrwx 1 geae users 375 Apr 17 10:04 dates.ksh

Apr 18 => No of files: 6
-rwxrwxrwx 1 geae users 555 Apr 18 01:12 IN.txt
-rwxrwxrwx 1 geae users 400 Apr 18 01:13 date_convert.ksh
-rw-rw-r-- 1 geae users 562 Apr 18 01:13 Updt_IN.txt
-rw-rw-r-- 1 geae users 590 Apr 18 02:43 Dir_File.txt
-rwxrwxrwx 1 geae users 1667 Apr 18 02:45 noofdir.ksh
-rw-rw-r-- 1 geae users 301 Apr 18 03:00 date.txt


So, How can list out the files based on the date?

Thanks and Regards,
Siva. P
Bangalore
# 2  
Old 04-18-2008
Script

This works for me:
Code:
ls -ltr | tail +2 > tempfile
token=`head -1 tempfile`
count=1
while read line
do
 dt=`echo $line | awk '{print $6" "$7}'`
 if [ "$dt" != "$token" ]
 then
  echo "$dt => No of files: $count"
  token=$dt
  count=1
 else
  count=`expr $count + 1`
 fi
done<tempfile

# 3  
Old 04-21-2008
One liner

Code:
ls -ltr | tail +2 | awk '{print $6" "$7}' | uniq -c

# 4  
Old 04-21-2008
list out the file group by date wise

Hi Krishnamath,

Thanks for your response, your command has retruning correct values but it retruend wrong output for some dates which is in single value date(Dec 5)

i have checked with some ordinary command

ls -rtl | grep "Dec 5" -- it won;t work why because we need to give 5 blank space in between month and date if the value of the date is single digit
instead of that we can use ls -rtl | grep "Dec 5" (its working)

how can we avoid the problem.

we should have to use the double blank spaces if the date of value is single digit.


Thanks and Regards,
Siva.P
Bangalore
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

2. Shell Programming and Scripting

Deleting lines based on a condition for a group of files

hi i have a set of similar files. i want to delete lines until certain pattern appears in those files. for a single file the following command can be used but i want to do it for all the files at a time since the number is in thousands. awk '/PATTERN/{i++}i' file (6 Replies)
Discussion started by: anurupa777
6 Replies

3. Shell Programming and Scripting

Reading 2 CSV files and filtering data based on group

I have two CSV files in the following format: First file: GroupID, PID:TID, IP, Port Sample data: 0,1000:11,127.0.0.1,445 0,-1:-1,127.0.0.1,800 1,1000:11,127.0.0.1,445 1,-1:-1,127.0.0.1,900 2,1000:11,127.0.0.1,445 2,-1:-1,180.0.0.3,900 Second file: IP,Port,PID Sample data... (6 Replies)
Discussion started by: rakesh_arxmind
6 Replies

4. Shell Programming and Scripting

finding the files based on date..

Hi to every one , i had ascenario like this.. i had path like export/home/pmutv/test/ in this i will recive 43 files daily with each file having that days date i.e like product.sh.20110512 like this i will 43 files every day i had to find the files. if files are avaliable i... (2 Replies)
Discussion started by: apple2685
2 Replies

5. UNIX for Dummies Questions & Answers

Remove files based on date

Hello team, I have a number of files in a folder which are dated yesterday and today.Can i remove all the files which i created today based on date?? is there any syntax for this ?? (1 Reply)
Discussion started by: kanakaraju
1 Replies

6. Shell Programming and Scripting

Deleting the files based on the date's

I have to write one script which will delete the files in the below passion. If today is 17-Feb-2010 then the script delete only 17-JAN-2010 files from the directory. Could you please help me, How will I delete the files when the year is leap year, if today is 30th Mar 2010 then how will... (1 Reply)
Discussion started by: kandi.reddy
1 Replies

7. Shell Programming and Scripting

Copy files based on date

Hi all i am having so many files in my directory.Is there any option to copy files based on date. example i am having file this -rw-rw-r-- 1 ram user 1 Feb 2 17:12 abc -rw-rw-r-- 1 ram user 1 Feb 2 17:12 bnw -rwxrwxr-x 1 ram user 21122 Feb 4... (3 Replies)
Discussion started by: suryanarayana
3 Replies

8. Shell Programming and Scripting

Get the newest files based on date

Hello friends, I'm learning to script, and I need help. How can I get the latest/newest files based on date? the format is as following: Feb 07 19:25 TESTPWD_file_1vk6pn40_19519_1 Feb 07 19:46 TESTPWD_file_1uk6pn40_19518_2 Feb 07 19:47 TESTPWD_file_20k6pn40_19520_2 Feb 07 19:56... (5 Replies)
Discussion started by: Beginer0705
5 Replies

9. Shell Programming and Scripting

Count of files based on date?

Hi Friends, Can anyone help me with this: To get the count of files that are existing in a directory created on a perticular date like in the example (01/08) .(having same pattern for the filename) ex: FileName Creted Date FILE001 01/08/2007 FILE005 ... (6 Replies)
Discussion started by: sbasetty
6 Replies

10. UNIX for Dummies Questions & Answers

Remove files based on date

I am trying to write a shell script that will remove files in a directory based on the date. For instance, remove all files older than yesterday. Any ideas? (4 Replies)
Discussion started by: hshapiro
4 Replies
Login or Register to Ask a Question