Find all files other than first two files dates & last file date for month


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Find all files other than first two files dates & last file date for month
# 8  
Old 04-14-2014
Also the main problem with below command
Code:
ls -lrt|grep ^- |grep " $i "|head -2|awk '{print $9}'

is only giving last two files . i want all files having date same as date of first two files.
similarly i want all files having date same as date of last file of month.

this i want for all months.

for example
jun 2012
mar 2013
apr 2013
mar 2014
apr 2014
# 9  
Old 04-14-2014
Post #1 you wrote:
Quote:
I need to find all files other than first two files dates & last file date for month and month/year wise list.
As I said in my preious post the easiest to cope with is to make a list with the unwanted and use that with a grep -v
If you want months per year, you will have to deal year by year...
# 10  
Old 04-14-2014
i will use
Code:
grep -v

that's not a issue.

could you send me command for all files with first two files dates & last file date for month

Note :suppose there 4 files with 1st mar 2014 then i want all 4 not the only 1st file
Hope you got my requirement
# 11  
Old 04-14-2014
Was in previous post:
Code:
for i in $(ls -l |awk '{print $6}'|sort|uniq ) # list what months we have in this directory
do
   echo MONTH=$i
   ls -lrt|grep ^- |grep " $i "|head -2|awk '{print $9}' >>test.0009 # 2 first of the month
   ls -lrt|grep ^- |grep " $i "|tail -1|awk '{print $9}' >>test.0009 #thelast for that month
done

Since this creates the exclusion list you would have to start by counting ow many files for that month and if more than 4 then create reacord in exclusion list
# 12  
Old 04-14-2014
So the code to produce exclusion list could look like:
Code:
for i in $(ls -l |awk '{print $6}'|sort|uniq )
do
   MIN=$(ls -l |grep " $i "|wc -l)
   echo MONTH=$i " MIN="$MIN
   if [ $MIN -gt 4 ]
   then
      ls -lrt|grep ^- |grep " $i "|head -2|awk '{print $9}' >>test.0009
      ls -lrt|grep ^- |grep " $i "|tail -1|awk '{print $9}' >>test.0009
   fi
done

# 13  
Old 04-14-2014
i think unfortunatly we both are not same page Smilie

1) This count 4 is not constant
2) for e.g. If there are two files with date 01/03/2014
3) for e.g. If there are three files with date 02/03/2014
4) for e.g. If there are six with date 15/03/2014
5) for e.g. If there are five files with date 31/03/2014

6) then i want files from above point 2),3)&5) (01/03/2014,02/03/2014,31/03/2014)
total 2+3+5= 10 files

7) the 6 files with date 15/03/2014 should not be there


so either give me list with above 10 files point #6

or

list with 6 files point #7
# 14  
Old 04-14-2014
Perhaps if you showed us your code, we could see if there is a faster way of doing...
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 find all files other than last two dates per month and year?

Hi All, lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 a.txt -rwxr-xr-x 1 user userg 1596 Mar 19 2012 b.txt -rwxr-xr-x 1 user userg 1596 Mar 22 2012 c.txt -rwxr-xr-x 1 user userg 1596 Mar 24 2012 d.txt... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

2. Shell Programming and Scripting

How to find all files other than first two dates & last date per month and year?

how to find all files other than first two dates & last date per month and year Hi All, lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 a.txt -rwxr-xr-x 1 user userg 1596 Mar 19 2012 b.txt -rwxr-xr-x 1 user userg ... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

3. Shell Programming and Scripting

How to find all files for same month and year?

Hi All, I find all files for same month and year lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 c.txt -rwxr-xr-x 1 user userg 1596 Mar 21 2012 d.txt -rwxr-xr-x 1 user userg 1596 Mar 22 2012 f.txt -rwxr-xr-x 1... (8 Replies)
Discussion started by: Makarand Dodmis
8 Replies

4. UNIX for Advanced & Expert Users

How to find last two files for a month?

Hi All, I need to find last two files for the month. lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 15:43 c.txt -rwxr-xr-x 1 user userg 1596 Mar 21 15:43 d.txt -rwxr-xr-x 1 user userg 1596 Mar 22 15:43 f.txt -rwxr-xr-x 1... (14 Replies)
Discussion started by: Makarand Dodmis
14 Replies

5. Shell Programming and Scripting

How to list files that are not first two files date & last file date for every month-year?

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

6. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

7. Shell Programming and Scripting

How to find the create time of a file if current date is in next month

Hi All, I want to find the time diffrence between currnt time and "abc.txt" file create time. I have solve that but if the abc.txt file created last month then is there any process to find the difftent? Exp: Create time of abc.txt is "Apr 14 06:48" and currect date is "May 17 23:47".... (1 Reply)
Discussion started by: priyankak
1 Replies

8. UNIX for Advanced & Expert Users

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

9. Solaris

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

10. Shell Programming and Scripting

Find all files by month

Hi, I am trying to do achieving of files by months. find /test -name \*.* -mtime +30 will give me the result of all modified files after 30 days. But lets say i want to list all files that is modified in last months... what is the command to do it? Thanks! (13 Replies)
Discussion started by: maldini
13 Replies
Login or Register to Ask a Question