Listing files of PAST 7 days and concatenate it...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing files of PAST 7 days and concatenate it...
# 1  
Old 09-15-2011
Listing files of PAST 7 days and concatenate it...

Hi All,

I want to list file of LAST 7 days acc. to its modified date and then concatinate.

I have following piece of code..
For concatenate
Code:
cat file1 file2 >> Output (For concatinating)
find . -mtime -7 -exec basename {} \;  (list past files but it is including . file also)

Plz help how to arrange it....
date -d '7 days ago (this function is not working on my OS)


Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 09-15-2011 at 09:30 AM.. Reason: code tags, see PM!
# 2  
Old 09-15-2011
You can do that all in one line, I'll show it step by step:


Quote:
Originally Posted by vivek1489
Code:
find . -mtime -7 -exec basename {} \;  (list past files but it is including . file also)

First, limit the search only to files, so directories like "." don't show up:

Code:
find . -mtime -7 -type f -exec basename {} \;

Print the found files names:

Code:
find . -mtime -7 -type f -print

Then do something with the files instead of just giving the name:

Code:
find . -mtime -7 -type f  -print -exec cat {} >> /some/output/file \;

Be sure to concatenate the files in a location other than where you search, because otherwise the new file will become concatenated to itself (which is very bad mojo for files).

I hope this helps.

bakunin
# 3  
Old 09-15-2011
try this ..
Code:
$ find . -type f -mtime -7 -exec cat {} > 7dayfilecontent \; 2>/dev/null


Last edited by jayan_jay; 09-15-2011 at 10:01 AM.. Reason: didnt see the above post :)
# 4  
Old 09-15-2011
Quote:
Originally Posted by jayan_jay
try this ..
Code:
$ find . -type f -mtime -7 -exec cat {} > 7dayfilecontent \; 2>/dev/null

This will overwrite the content of "7dayfilecontent" over and over again. Further the error channel is not there to be thrown away but to be observed - if something shows up there then probably so for a reason. Unless you don't know for sure you don't need it you shouldn't do that.

baknin
# 5  
Old 09-15-2011
thanks for help...
how do I get files for concatinating
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Should pick latest file within past 3 days using UNIX script and perform steps in message below.

Hi , Can anyone help me how do perform below requirement in unix. Step1:we will receive multiple files weekly with same name(as below) in a folder(In folder we will have other files also def.dat,ghf.dat) Filenames: 1) abc_20171204_052389.dat 2)abc_20171204_052428.dat DON'T modify... (23 Replies)
Discussion started by: sunnykamal59
23 Replies

2. Shell Programming and Scripting

Listing files older than 30 days

Hi, Could someone help me that what the problem is in this code? #!/bin/sh FOLDER=/abc/datasource/checkstatus TIMESTAMP=$(date +%s) for filename in $(find $FOLDER -maxdepth 1 -type f -name "CHECK_STATUS*"); do f1=$($filename -Eo "{4}+") f2=$(date -d "$f1" +%s) if... (11 Replies)
Discussion started by: Home
11 Replies

3. UNIX and Linux Applications

From past 10 days my one job is taking lots of time

One of my job is taking long running time. I need to identify from the unix log file can you please help how to troubleshoot. (1 Reply)
Discussion started by: Nsharma3006
1 Replies

4. Shell Programming and Scripting

Seven days past date from current date

hi all.. i want 2 know how 2 find 7days past date from current date.. when i used set datetime = `date '+%m%d%y'` i got 060613.. i just want to know hw to get 053013.. i tried using date functions but couldnt get it :( i use c shell and there is no chance that i can change that ..... (3 Replies)
Discussion started by: Rahul619
3 Replies

5. HP-UX

listing processes older than n days

Hello; trying to find processes older than n days, mostly user shells Tried the following code on 11.31 box: in this case older than 5 days UNIX95= ps -ef -o user,pid,ppid,cpu,etime,stime | grep "-" | awk '{print $2}' | xargs ps -ef|grep -v '?' |\ awk '$5 !~ ""' | awk '($5 ~ "$(date "+%b")")... (6 Replies)
Discussion started by: delphys
6 Replies

6. Shell Programming and Scripting

How to find a date which is 7 days past when given current date

hii all. I have to get the date of the 7th day past from the current date. if i give the current date as sep 3 then i must get the date as 27th of august. can we get the values from the "cal" command. cal | awk '{print $2}' will this type of command work. actually my need is if today is... (17 Replies)
Discussion started by: ladtony
17 Replies

7. Shell Programming and Scripting

find files from the past 7 days

Hi All, I have a file which contains the listing of another directory: >cat list.dat -rwxr-xr-x 1 test staff 10240 Oct 02 06:53 test.txtdd -rwxrwxrwx 1 test staff 0 Oct 04 07:22 test.txx -rwxrwxrwx 1 test staff 132 Sep 16 2007 test_tt.sh... (6 Replies)
Discussion started by: deepakgang
6 Replies

8. UNIX for Dummies Questions & Answers

creating a CSV file for past 7 days

I have a requirement which will select the files with a specific naming convention which got created in past 7 days in a specific directory.Lets say the directory is /data/XYZ and the file names follow the below nomenclature like Daily_File*.txt I just need to create one CSV file which will... (12 Replies)
Discussion started by: dr46014
12 Replies

9. UNIX for Dummies Questions & Answers

Find files older than 5 days and remove tem after listing

need help with this ... Find files older than 5 days and remove tem after listing list "test" file older than 5 days and then remove them (1 Reply)
Discussion started by: ypatel6871
1 Replies
Login or Register to Ask a Question