- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to grep a file name out of list of files withi...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2015 05:33 AM - last edited on 05-03-2015 08:09 PM by Maiko-I
04-28-2015 05:33 AM - last edited on 05-03-2015 08:09 PM by Maiko-I
how to grep a file name out of list of files within time period
suppose I have lfollowing ist of files:
-rw-r--r-- 1 appltest dba 1078 Apr 28 11:27 o40571618.out
-rw-r--r-- 1 appltest dba 0 Apr 28 11:33 o40571615.out
-rw-r--r-- 1 appltest dba 1685 Apr 28 11:38 o40571622.out
-rw-r--r-- 1 appltest dba 0 Apr 28 11:43 o40571620.out
-rw-r--r-- 1 appltest dba 0 Apr 28 11:54 o40571623.out
-rw-r--r-- 1 appltest dba 0 Apr 28 12:04 o40571624.out
-rw-r--r-- 1 appltest dba 0 Apr 28 12:14 o40571625.out
-rw-r--r-- 1 appltest dba 0 Apr 28 12:24 o40571626.out
Now I need to know all files between time periods Apr 28 time between 11:38 & 12:04
What would be the right command to know this files as per given time periods?
Thanks.
P.S. This thread has been moved from HP-UX > System Administration to HP-UX > languages. - Hp Forum Moderator
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2015 06:14 AM
04-28-2015 06:14 AM
Re: how to grep a file name out of list of files within time period
You could try the following using awk...
find . -mtime 0 -ls | awk '$10~/11:(3[8-9]|[4-5][0-9])|12:0[0-4]/'
For example...
# find . -mtime 0 -ls | awk '$10~/11:(3[8-9]|[4-5][0-9])|12:0[0-4]/'
73774 1 -rw-r--r-- 1 root sys 5 Apr 28 11:38 ./test
73775 1 -rw-r--r-- 1 root sys 6 Apr 27 11:52 ./test2
73771 1 -rw-r--r-- 1 root sys 6 Apr 27 12:04 ./test3
A quick resolution to technical issues for your HP Enterprise products is just a click away HPE Support Center Knowledge-base
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2015 06:18 AM - edited 04-28-2015 06:23 AM
04-28-2015 06:18 AM - edited 04-28-2015 06:23 AM
Re: how to grep a file name out of list of files within time period
Because human-readable timestamps are very difficult to compare especially between months and years, you'll have to do this in several steps. First, your script will have to create two reference files using touch. The first file should have the timestamp of the older range and the other has the newer timestamp. For your requirement:
# cd /somedir
# touch -t 201504281138 oldref # touch -t 201504281204 newref
Now you would use find to locate files that are newer that the oldref file, remember those filenames, then search that list for files that are not newer than the newref file.
# NEWER=$(find . -type f -newer oldref) # find $NEWER ! -newer newref
This is especially useful in comparing files more than a year old where ls -l changes to MON DAY YEAR rather than MON DAY HR:MIN. The -newer comparison is accurate to the second. Note that the "! -newer newref" test will always include the newref file.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2015 06:35 AM
04-28-2015 06:35 AM
Re: how to grep a file name out of list of files within time period
I do something very similar to Bill e.g.
# touch -t 201504281300 /tmp/starttime
# touch -t 201504281350 /tmp/endtime
# find /yourdir -name "*yourfile" -newer /tmp/starttime ! -newer /tmp/endtime
A quick resolution to technical issues for your HPE products is just a click away HPE Support Center Knowledge-base
See Self Help Post for more details
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2015 11:35 PM
04-28-2015 11:35 PM
Re: how to grep a file name out of list of files within time period
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2015 03:14 AM
04-29-2015 03:14 AM
Re: how to grep a file name out of list of files within time period
Hi,
One more help pls.
All files generated at night 11:46 and anyone of these files has a string 'mismatch'.
How I can find this file only?
There may be multiple files generated at that time 11:46 night but only one file contain the string 'mismatch' within the file.
I need to know this file only.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2015 04:18 AM - edited 04-29-2015 04:20 AM
04-29-2015 04:18 AM - edited 04-29-2015 04:20 AM
Re: how to grep a file name out of list of files within time period
>> All files generated at night 11:46...
Don't you mean 23:46 for 'night'?
11:46 is about noon rather than night.
This is fairly simple:
cd /someDIRtoSEARCH for MYFILE in $(ls -l | awk '/ 23:46 /{print $NF}') do [[ $(grep -c "mismatch" $MYFILE) -gt 0 ]] && echo "found it: $MYFILE" done
If "mismatch" might also be MISMATCH, change the grep option to -ic to ignore UPPER/lower differences.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2015 09:18 PM
04-29-2015 09:18 PM
Re: how to grep a file name out of list of files within time period
Dear Bill,
Your latest post is very much working as per my requirement. I need one modification in the script.
It should only pick up the latest date file when the script runs because earlier dates similar files are also present in the directory.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2015 10:18 PM
05-04-2015 10:18 PM
Re: how to grep a file name out of list of files within time period
>I do something very similar to Bill
Not similar but much much better. You only use one pass of find.
>explain $10 ~ /11 .../ what exactly its meaning?
Field $10 matches the specially tailored given ERE pattern, useless in the more general case.
Basically this is silly stuff trying to do pattern matching to solve a range check for between.
> [[ $(grep -c "mismatch" $MYFILE) -gt 0 ]] && echo "found it: $MYFILE"
Better to use grep -q directly:
grep -q "mismatch" $MYFILE && echo "found it: $MYFILE"
-q is also better since it stops when it finds the first match and not after reading the whole file!
>It should only pick up the latest date file
How do we determine "latest date file"?
Do we pick only the newest file and if that has "mismatch"?
Or only check the N newest files?