How to find last two files for a month?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to find last two files for a month?
# 8  
Old 04-10-2014
Try
Code:
ls -lt | grep Mar | tail -n+3

# 9  
Old 04-10-2014
this is giving error
usage: tail [+/-[n][lbc][f]] [file]
tail [+/-[n][l][r|f]] [file]
# 10  
Old 04-10-2014
man tail:
Quote:
-n, --lines=K
output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth
for tail (GNU coreutils) 8.20
So -n+3 gives you all lines except for the first two... Adapt for your tail version.
# 11  
Old 04-10-2014
Sorry ,

I am using unix solaris 5.8 ksh
# 12  
Old 04-10-2014
Using a small circular buffer, files from multiple months (and years) can be handled in a single pass:
Code:
ls -lrt | awk 'm!=$6 {m=$6; i=0} ++i>2 {print a[i%2]} {a[i%2]=$0}'

Since the date format is locale dependent, you may want any ls-based solution to explicitly set the locale.

I barely tested it, and then only in my locale.

Regards,
Alister
# 13  
Old 04-11-2014
Hi Alister,

Result by your code is partialy correct.

i want files not to disaply of first two file dates & last file date for a month.

Suppose there are 4 files for 1 Apr 2014 date & 4 files 2 Apr 2014 & 2 files 30 Apr 2014 then these all 10 files should not get displayed.

Regards,
Dodmis
# 14  
Old 04-11-2014
Post #1 states that you only want to keep the last two files of each month.

Posts #5 and #7 indicate the inverse: the last two files of each month should be discarded.

Now, with post #13, you present a third permutation which appears to require keeping all files except those whose dates match the first 2 days of the month and the last day of the month.

If you want volunteers to help you freely, the least you can do is present a single, coherent problem statement. Speaking for myself, you're not paying me enough to track this moving target.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need last month files after 10th of every month

Hi, I need all file names in a folder which has date >= 10th of last month, Example : files in folder AUTO_F1_20140610.TXT BUTO_F1_20140616.TXT CUTO_F1_20140603.TXT FA_AUTO_06012014.TXT LA_AUTO_06112014.TXT MA_AUTO_06212014.TXT ZA_AUTO_06232014.TXT Output: AUTO_F1_20140610.TXT... (9 Replies)
Discussion started by: nani1984
9 Replies

2. 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

3. 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

4. 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

5. UNIX for Advanced & Expert Users

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

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... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

6. Shell Programming and Scripting

how can i find the third friday of each month?

Help please! I need to read the calendar and put the date of the third Friday of each month into a variable for comparison in an "if" statement. How would I do this? Thnx, leslie02 (10 Replies)
Discussion started by: leslie02
10 Replies

7. 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

8. 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

9. HP-UX

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