December 14, 2010

[SOLVED] Unix: search files between TIME1 and TIME2 with string 123456 in it

e.g.

TIME1 = 2010-11-02 00:00
TIME2 = 2010-11-24 00:00
SEARCHSTRING= 123456
File pattern "PATTERN1231313123.txt"

create files with right timestamps
 touch -t 11020000 /tmp/stamp_2010-11-02_0000
touch -t 11240000 /tmp/stamp_2010-11-24_0000

check your list of files if it is right
find . -regextype posix-awk  -regex '^\./PREFIX[0-9]*.txt' -newer /tmp/stamp_2010-11-02_0000 -and -not -newer /tmp/stamp_2010-11-24_0000 -ls

export your list
 find . -regextype posix-awk  -regex '^\./PREFIX[0-9]*.txt' -newer /tmp/stamp_2010-11-02_0000 -and -not -newer /tmp/stamp_2010-11-24_0000 -exec grep --color "123456" {} \; > /tmp/mydata_123456.csv

Source: serverfault.com, gnu.org

No comments:

Post a Comment