Find files greater than a particular date in filename.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find files greater than a particular date in filename.
# 8  
Old 07-30-2012
You don't need the int() for this comparison, and it will hurt you if you're not using an awk that uses 64-bit ints. Just use:
Code:
ls abc.* | awk -F'.' '$2>'201206000000' {print $0}'

This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 07-30-2012
Hi Don
Thanks for the reply. That worked.
But one small change in my question. Sorry for not letting you know this earlier.
My file names are
Code:
abc.C201206015423.txt
abc.C201207013456.txt
abc.C201202011234.txt
abc.C201201024321.txt
efg.C201202011234.txt
efg.C201201024321.txt

Code:
ls abc.* | awk -F'.' '$2>'C201206000000' {print $0}'

above didnt work.

Thanks

Last edited by Franklin52; 07-31-2012 at 05:35 AM.. Reason: Please use code tags for data and code samples
# 10  
Old 07-30-2012
Not surprising. With a numeric string 201206000000, the value being compared is 201206000000. With the string C201206000000, awk sees a variable name and since the variable hasn't been set, the value being compared is 0. You need to compare a string to a string, so try:
Code:
ls abc.* | awk -F'.' '$2>"C201206000000" {print $0}'

Presumably at some point you'll want to put this in a script where you have the start date in a shell variable (e.g., STARTDATE). When you get there, you'll probably want something like:
Code:
STARTDATE=20120600000000
ls *.*.txt | awk -F. '$2 > "C'$STARTDATE'" {print}'

This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 07-30-2012
What shell do you use? Do you want a script that'd list these certain files, or a function you'd use from the command line?
This User Gave Thanks to neutronscott For This Post:
# 12  
Old 07-30-2012
Hi
I need a script and it is c shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To find files having filename containing specific date format

Hi, I have a requirement to create a shell script(tcsh) that finds all the files in a directory having the file name containing date format "YYYYMMDDHHMM" and extract the date time part ""YYYYMMDDHHMM" for further processing. Could you please have any idea on this. trades_201604040000.out... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

2. Shell Programming and Scripting

Find file by filename or with newest modified date

Hi, I have a directory that has numerous files in it, and there is two which are named "filerec_ddmmyyHH24MMSS" by the time they are created so "filerec_010615012250" was created at 01:22:50 on 1st June 2015. I need to find the most recently created of those 2 files and get the contents of... (4 Replies)
Discussion started by: finn
4 Replies

3. Shell Programming and Scripting

Please help list/find files greater 1G move to different directory

I have have 6 empty directory below. I would like write bash scipt if any files less "1000000000" bytes then move to "/export/home/mytmp/final" folder first and any files greater than "1000000000" bytes then move to final1, final2, final3, final4, final4, final5 and that depend see how many files,... (6 Replies)
Discussion started by: dotran
6 Replies

4. Shell Programming and Scripting

Find the latest file based on the date in the filename

Hi, We've a list of files that gets created on a weekly basis and it has got a date and time embedded to it. Below are the examples. I want to find out how to get the latest files get the date and time stamp out of it. Files are PQR123.PLL.M989898.201308012254.gpg... (1 Reply)
Discussion started by: rudoraj
1 Replies

5. Shell Programming and Scripting

Find file that matches today's date in filename and move to /tmp in bash

I'm having problems with my bash script. I would like to find a file matching today's date in the filename, i.e. my_file_20120902.txt and then move it to a different directory, i.e. /tmp. Thanks. (1 Reply)
Discussion started by: jamesi
1 Replies

6. UNIX for Dummies Questions & Answers

List of Files which are Greater then a specific date

A newbie question... I need to get a list of the Files and folders which are greater then a specific date. I want write the output to a Text file. What I know ls -lrt gives me list of all the files ordered by date. Also ls > fileName will write the results to a text file. Please help (6 Replies)
Discussion started by: rkaif
6 Replies

7. UNIX for Dummies Questions & Answers

How do I find files which are older than 30 days and greater than 1GB

Hi All, I know the separate commands for finding files greater than 30 days and finding files greater than 1GB. How do I combine these two commands? Meaning how do I find files which are > 1GB and older than 30 days? ;) (4 Replies)
Discussion started by: Hangman2
4 Replies

8. Shell Programming and Scripting

Trying to find files equal to and greater than

Hi Guys and Gals, I'm having some difficulty putting this check into a shell script. I would like to search a particular directory for a number of files. The logic I have is pretty simple: Find file named *.txt that are newer than <this file> and count them If the number of files is equal to... (4 Replies)
Discussion started by: bbbngowc
4 Replies

9. Shell Programming and Scripting

Important finding --- find files greater than 1 MB

as we can find file greater than 1 MB with find command as: find /dir -name '*' -size +1M find /dir/* -name '*' -size +1M but wats its doing is , its finding files only in current directory not in sub-directories. i want files from sub-directories too. Please help... Thanx in... (3 Replies)
Discussion started by: manoj_dahiya22
3 Replies

10. UNIX for Advanced & Expert Users

find formatted filename with date time

Hi, I operate and use HF radars along the California coast for ocean surface currents. The devices use Mac OS as the control and logging software. The software generates thousands of files a week and while I've used PERL in the past to solve the problems of finding files I come to realize some... (6 Replies)
Discussion started by: dpath2o
6 Replies
Login or Register to Ask a Question