Find and grep issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and grep issue
# 1  
Old 06-11-2014
Find and grep issue

Hi,

I need to find all file in a directory dated yesterday and not today and then zip them into a zip file @ new location without affecting [touching] the existing files.

My OS : SunOS Sparc 5.10

Last edited by mohtashims; 06-11-2014 at 01:53 PM..
# 2  
Old 06-11-2014
What have you tried?

What isn't working in what you have tried?
# 3  
Old 06-11-2014
Quote:
Originally Posted by Don Cragun
What have you tried?

What isn't working in what you have tried?

I tried all options in here but could not make it.

Help - compress file one day ago

with mtime -1 it yields all files back 24 hrs including today's which is not what i need.

Also, the gzip option zips the current files while i am looking for the files to be unaffected and get copied to a zip in a separate location all together.

With some commands -daystart does not work for me.
# 4  
Old 06-12-2014
This can be tricky in Solaris I'd suggest using a perl program to get the required date strings

Save this as gettime.pl:

Code:
#!/bin/perl
use POSIX; print strftime('%Y%m%d0000.00', localtime(time() - $ARGV[0]));

Then you can use this script to find and tar+gzip your files:

Code:
FOLDER=/path/to/files
ZIPFOLDER=/path/for/zip/files
YESTERDAY=$(./gettime.pl 86400)
TODAY=$(./gettime.pl 0)
touch -t $YESTERDAY /tmp/yesterday.$$
touch -t $TODAY /tmp/today.$$

FILES=$(find "$FOLDER" -type f -newer /tmp/yesterday.$$ ! -newer /tmp/today.$$ -print)
if [ -n "$FILES" ]
then
    tar -cf "$ZIPFOLDER/zip_$(date +%Y%m%d.tar)" $FILES
    gzip "$ZIPFOLDER/zip_$(date +%Y%m%d.tar)"
fi

rm /tmp/yesterday.$$
rm /tmp/today.$$

Just be careful running this very close to midnight - it may turn back into a pumpkin Smilie
This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 06-12-2014
Could you experiment with -mtime +0 too? Something like this:-
Code:
find . -type f -mtime +0 -mtime -1


Robin
# 6  
Old 06-13-2014
Quote:
Originally Posted by rbatte1
Could you experiment with -mtime +0 too? Something like this:-
Code:
find . -type f -mtime +0 -mtime -1

Robin
That doesn't work, will never return anything.
-mtime works with fullday distances from today.
Code:
find . -type f -mtime +0 -mtime -2

is identical with
Code:
find . -type f -mtime 1

(The integer 1 is >0 and <2). Meaning files that are between 1 and 2 days old.
And
Code:
find . -type f -mtime 0 -ls

lists files that are between 0 and 1 day old.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Issue with Grep

Hi guys, Hope someone can help me with this - I'm sure it's fairly simple but it's driving me mad! (forgive the coding - still new on scripting - come from Windows) I have the following coding for checking whether I want to include a line in a file:- EXTRACT_Date=$(date --date="${PERIOD}"... (6 Replies)
Discussion started by: NickF
6 Replies

2. Shell Programming and Scripting

Issue in grep

i have following pattern in file s6:s2 s2:s4 s1:s2:s3:s4:s5:s6 s1 . . Now i want to find occurence of each record in file like s6:s2 occurs twice {once in first record and both occur in 3 record as well} so output should be s6:s2 2 s2:s4 2 s1:s2:s3:s4:s5:s6 :1 s1 : 2 ... (7 Replies)
Discussion started by: sharad.40216
7 Replies

3. Shell Programming and Scripting

Issue with grep

Hi there, I need to grep out 1 line of a changing file. Any help would be much appreciated. code: xterm -hold -e tail -f /var/lib/dhcp3/dhcpd.leases | grep client-hostname &>/dev/null & The trouble is it shows the contents of the entire lease file. I just want to show the line... (5 Replies)
Discussion started by: digitalviking
5 Replies

4. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

5. Shell Programming and Scripting

Grep issue

Hi All I have a file containing following records: $HEW_TGT_DB2_USER=hbme_bi2 $prmAttunityUser=ais $DS_USER=hbme_bi2 $prmStgUser=hbme_bi2 $prmuser=hbme_bi2 $prmStgPass=hbme_bi2 $prmpwd=hbme_bi2 $prmAttunityUser=ais Say suppose the name of the file is test4.txt When i fire this... (2 Replies)
Discussion started by: vee_789
2 Replies

6. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

7. UNIX for Dummies Questions & Answers

Grep issue

more Hello.txt it was a sunny way and i was about to go home. I need to grep and redirect to a new file all the text between 'sunny' and 'go' string above. Note: There may be multiple lines in between the string i need to grep between. If there are multiple 'go' strings it should grep till... (9 Replies)
Discussion started by: mohtashims
9 Replies

8. Shell Programming and Scripting

grep issue

The below command is not working stackmem="$(pmap $1 | grep -i '' | awk '{print $2}'| tr -d ' K')" I need to grep strictly for ----> Regards, Mohtashim (2 Replies)
Discussion started by: mohtashims
2 Replies

9. Shell Programming and Scripting

Grep Issue

<record> <set> <termId>1234</termId> <termType>First</termType> </set> <set> <termId>5678</termId> <termType>Second</termType> </set> </record> This is saved in record.xml Hi I have this sample XML that i am grepping using a shell program. The objective of the task is - based... (7 Replies)
Discussion started by: revertback
7 Replies

10. UNIX for Dummies Questions & Answers

issue with grep

using grep, i have a file emp.lst, and i want all those records where "S" or "s" (capital or small) is not there i used this grep emp.lst when i use grep emp.lst i am getting rows with S..but why negate (^) is not working? (3 Replies)
Discussion started by: soujanya_srk
3 Replies
Login or Register to Ask a Question