Sponsored Content
Top Forums Shell Programming and Scripting Find Files with a input in directories Post 302729469 by migurus on Friday 9th of November 2012 08:05:52 PM
Old 11-09-2012
I understood the problem lays in the fact that a single file can span several days worth of data, such as

Quote:
Code:
sensor1_log_from_2012_07_01_10_:_30_to_2012_07_03_10_:_30

You need a method to find appropriate file for a given date, if I am not mistaken.

I propose to use gawk capacity to manipulate dates and use unix epoch date form, which can be compared arithmetically.

1) convert given date/time to epoch form
2) go through files and for each extract start_time and end_time from the file name and using a mktime function convert both into the unix epoch time
3) if given_time >= start_time and given_time <= end_time then you got the file needed.

Note: I'm not sure if awk/nawk has mktime function, that is why emphasis on gawk.

To demonstrate I put a simple script:

Code:
#!/bin/ksh
s="sensor1_log_from_2012_07_01_10_:_30_to_2012_07_03_10_:_30"
echo $s|
gawk '
BEGIN{
        qry1_time = mktime("2012 06 20 18 30 00");
        qry2_time = mktime("2012 07 02 10 00 00");
        qry3_time = mktime("2012 07 03 22 45 00");
}
{
n=split($0, arr, "_");
str_fr_time = arr[4]" "arr[5]" "arr[6]" "arr[7]" "arr[9]" 00"
str_to_time = arr[11]" "arr[12]" "arr[13]" "arr[14]" "arr[16]" 00"
fr_time = mktime(str_fr_time);
to_time = mktime(str_to_time);
print "FR:"str_fr_time
print "TO:"str_to_time
if(qry1_time >= fr_time && qry1_time <= to_time)  
        print "OK for " strftime("%x %X", qry1_time);
else 
        print "NO for " strftime("%x %X", qry1_time);
 
if(qry2_time >= fr_time && qry2_time <= to_time)  
        print "OK for " strftime("%x %X", qry2_time);
else 
        print "NO for " strftime("%x %X", qry2_time);
if(qry3_time >= fr_time && qry3_time <= to_time)  
        print "OK for " strftime("%x %X", qry3_time);
else 
        print "NO for " strftime("%x %X", qry3_time);
 
}'

And here is the output
Code:
 
FR:2012 07 01 10 30 00
TO:2012 07 03 10 30 00
NO for 06/20/12 18:30:00
OK for 07/02/12 10:00:00
NO for 07/03/12 22:45:00

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find files in Directories

Hello, We have in a file a list of the path of files from one server. We want to search if these files exist on another server , but the path on this new server isn't the same. We want to use the command "awk" but there isn't the god way. Example: on server 1 in a file : listServer1.txt... (4 Replies)
Discussion started by: steiner
4 Replies

2. UNIX for Advanced & Expert Users

find -type d returning files as well as directories

Can anyone see why the following command returns all files and not just the directories as specified? find . -type d -exec ls -F {} \; Also tried find . -type d -name "*" -exec ls -F {} \; find . -type d -name "*" -exec ls -F '{}' \; -print Always returns all files :-\ OS is... (2 Replies)
Discussion started by: tuns99
2 Replies

3. Homework & Coursework Questions

Find and delete empty files and directories

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Need to make a script, to remove all empty files and folders from current category. It also should show the name... (2 Replies)
Discussion started by: Itixop
2 Replies

4. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

5. Shell Programming and Scripting

Script to go Into Directories and Find/Delete files

I have a task, I usually do manually, but with growing responsibilities I tend to forget to do this weekly, I want to write a script that automates this, but I cant seem to work it out in my head, I have the shell of it out, but need help, and you guys have helped me with EVERY problem I have... (5 Replies)
Discussion started by: gkelly1117
5 Replies

6. Shell Programming and Scripting

Find only files/directories with different permissions/owners

My git post-update has the following lines in it to make sure the permissions are set right: find /usr/local/apache/htdocs -type d -print0 | xargs -0 chmod 755 find /usr/local/apache/htdocs -type f -print0 | xargs -0 chmod 644 chown -R apache:apache /usr/local/apache/htdocsThe only problem is... (5 Replies)
Discussion started by: dheian
5 Replies

7. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

8. UNIX for Dummies Questions & Answers

Find Files In A List with known Partial Directories

First I'm new to Linux and have used the find command pretty often but this is where I've hit a snag. I have a file that contains 3500 files that I want to find and then eventually copy to my own directory (these files are all on a shared directory at work atm). Our work computer are huge and... (2 Replies)
Discussion started by: Myrona
2 Replies

9. UNIX for Dummies Questions & Answers

Loop over certain user directories and find files

Hello I have user directories that contain /temp directory. Example folders: /user1/temp/ /user2/temp/ /user3/temp/ How can i loop over all user directories and find all files only in their /temp folder? Thanks a lot for help! (3 Replies)
Discussion started by: flavius42
3 Replies

10. Shell Programming and Scripting

Find common files between two directories

I have two directories Dir 1 /home/sid/release1 Dir 2 /home/sid/release2 I want to find the common files between the two directories Dir 1 files /home/sid/release1>ls -lrt total 16 -rw-r--r-- 1 sid cool 0 Jun 19 12:53 File123 -rw-r--r-- 1 sid cool 0 Jun 19 12:53... (5 Replies)
Discussion started by: sidnow
5 Replies
GETBUILDLOG(1)						      General Commands Manual						    GETBUILDLOG(1)

NAME
getbuildlog - download build logs from Debian auto-builders SYNOPSIS
getbuildlog package [version-pattern] [architecture-pattern] DESCRIPTION
getbuildlog downloads build logs of package from Debian auto-builders. It downloads build logs of all versions and for all architectures if version-pattern and architecture-pattern are not specified or empty, otherwise only build logs whose versions match version-pattern and build logs whose architectures match architecture-pattern will be downloaded. The version and architecture patterns are interpreted as extended regular expressions as described in grep(1). If version-pattern is "last" then only the logs for the most recent version of package found on buildd.debian.org will be downloaded. If version-pattern is "last-all" then the logs for the most recent version found on each build log index will be downloaded. OPTIONS
-h, --help Show usage information and examples. -V, --version Show version and copyright information. EXAMPLES
getbuildlog hello 2.2-1 amd64 Download amd64 build log for hello version 2.2-1. getbuildlog glibc "" mips.* Download mips(el) build logs of all glibc versions. getbuildlog wesnoth .*bpo.* Download all build logs of backported wesnoth versions. AUTHOR
Written by Frank S. Thomas <fst@debian.org>. DEBIAN
Debian Utilities GETBUILDLOG(1)
All times are GMT -4. The time now is 08:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy