List the files of previous day


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List the files of previous day
# 1  
Old 07-26-2012
Java List the files of previous day

I am using KSH.

Code:
 
d=date | nawk '{ print $2,$3-1}'
ls -lrt SystemOut* | nawk '/d/{print $NF}'

I am trying to list the files of previous day but it doesn't seem to be working and i am also not getting an error.

result is blank.Need help.
# 2  
Old 07-26-2012
Code:
d=date | nawk '{ print $2,$3-1}' 
ls -lrt SystemOut* | nawk '$0 ~ d {print $NF}' d="${d}"

What will happen on the 1-st of a month?
What will happen on the 1-st of March of a leap/non-leap year?
# 3  
Old 07-27-2012
Hi Vgresh,

Could you please explain what does d="${d}" do?

Were you asking a question to me in the above post ?

---------- Post updated at 01:13 PM ---------- Previous update was at 11:17 AM ----------

Code:
 
d=date | nawk '{ print $2,$3-1}' 
ls -lrt SystemOut* | nawk '$0 ~ d {print $NF}' d="${d}"

It is throwing a error empty regular expression. I don't know how to proceed. Your guidance will be appreciated.

Last edited by Scott; 07-27-2012 at 10:13 AM.. Reason: Code tags
# 4  
Old 07-27-2012
Code:
d=`date | nawk '{ print $2,$3-1}'`
ls -lrt SystemOut* | nawk '$0 ~ d {print $NF}' d="${d}"

yes, I was asking you..........
# 5  
Old 07-28-2012
Quote:
Could you please explain what does d="${d}" do?
Code:
 d="${d}"

This assigns the value of variable $d defined in script as the previous day to variable d in awk.

Code:
 $0 ~ d

The above is a containment test which will be true if the value of d matches anywhere on the line returned from ls command.

To match only those files that were created/modified based in the value of $d, you should use field $7 (the day), not $0.

Code:
 ls -lrt SystemOut* | nawk '$7 ~ d {print $NF}' d="${d}"

The above exectutes fine on Solaris.

Note that vgersh99's questions still apply.
# 6  
Old 07-29-2012
If you don't need awk, try this:
Code:
find . -daystart -mtime -2 ! -mtime -1 -ls

Will work in leap years and on month's first...
# 7  
Old 07-29-2012
Quote:
Originally Posted by vgersh99
Code:
d=date | nawk '{ print $2,$3-1}' 
ls -lrt SystemOut* | nawk '$0 ~ d {print $NF}' d="${d}"

What will happen on the 1-st of a month?
What will happen on the 1-st of March of a leap/non-leap year?
vgersh99,
Nothing will happen with the code you supplied.

If you change it to:
Code:
d=$(date | nawk '{ print $2,$3-1}')
ls -lrt SystemOut* | nawk -v d="${d}" '$0 ~ d {print $NF}'

It will find the files you want if you run it on days 11-31 in any month.
The first line calls nawk to convert the output of the date command (which today would be something like "Sun Jul 29 10:07:09 PDT 2012") to "Jul 28".

But, it will also list any other lines that contain "Jul 28" in the file name instead of in the date field. It won't work on the day 1-10 of any month because the awk command:
Code:
print $2,$3-1

puts one space between the two values being printed, but the ls -l output has two spaces between the abbreviated month and the day for days 1 through 9 each month (which will keep the match of $0 to the awk variable d to fail).

Both of these problems can be fixed by keeping the abbreviated month name and the day of the month separate and matching them agains the 6th and 7th fields, respectively, in the output of ls instead of matching the combined fields agains the entire line.

But, it still won't work on the first of any month because the first command on the first of any month will set d to <MonthAbbreviation><space>0 and you'll never find ls -l output with a 0 as the day. So, using this method, you need to make your first awk command smart enough to convert the things like "Sun Jul 1 10:07:09 PDT 2012" to "Jun 30" instead of "Jul 0". If you have understood this much, I assume you now understand why leap years add to this complexity when calculating the previous day for March 1st.

The find -daystart primary suggested by RudiC with -mtime 1 would take care of this on some implementations, but I believe you said on another thread that you were running on OS/X and awk on OS/X doesn't provide the daystart primary.

On OS/X, the following should do what you want:
Code:
#!/bin/ksh
touch datestamp$$
touch -A -240000 datestamp$$
set -- $(ls -l datestamp$$)
rm datestamp$$
ls -lrt SystemOut*|awk -v m=$6 -v d=$7 '$6 ~ m && $7 ~ d {print $NF}'

This User Gave Thanks to Don Cragun For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find list of files modified for a given day ?

find list of files modified for a given day ? if i have 10 files in my directory, i have modified only 5 ... how to display only modified files ? (1 Reply)
Discussion started by: only4satish
1 Replies

2. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

3. Shell Programming and Scripting

Command to list current day files only

Hi All, can anyone pls share the command to list the files of current day only. i want to check if there are any files in a particular directory which are not of current date. (6 Replies)
Discussion started by: josephroyal
6 Replies

4. Shell Programming and Scripting

Script to check if last modified day is previous day

Hi, I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it. For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Discussion started by: hegdepras
1 Replies

5. Shell Programming and Scripting

getting previous day.

Hi, i am developing a script for my project. In my script i need to check some conditions based upon some values. in that one value is the previous date. with the previous date i need to check and process some values. I have a function with me retrieve the yesterdays date. But now i have a... (6 Replies)
Discussion started by: intiraju
6 Replies

6. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

7. UNIX for Dummies Questions & Answers

sample script to archive & move previous day syslog files

hi all. Please help me with archiving previous day syslog files. the files have no extension and have the format YYYY-MM-DD. I want to archive the file then move it to some other machine. thanks. (2 Replies)
Discussion started by: coolatt
2 Replies

8. Shell Programming and Scripting

Download previous day files through FTP

Hi All, I have a scenario where I need to download the previous day modified files from other server to my server through FTP . Could any one please send me the shell script for the same. I used the following but I dont know how to proceed after this. ftp -n -i -v $IP <<ENDOFinPUT >>... (3 Replies)
Discussion started by: sarathchandrach
3 Replies

9. Shell Programming and Scripting

last working day of previous month

Hi, I want a script(ksh) to see if today is the last working day(Mon-Fri) of the month. If it is the last working day I need to print current date, else I need the last working day of previous month. Thanks in advance. (1 Reply)
Discussion started by: rspk_praveen
1 Replies

10. Shell Programming and Scripting

next/Previous business day

Hello, Can you please help me how do i get previous and next working day of the week for a given date excluding saturday and sunday. Ex: if the given date is monday, i should get friday and tuesday's date if the given date is friday, i should get thrusday and monday's date. Thanks,... (4 Replies)
Discussion started by: kotasateesh
4 Replies
Login or Register to Ask a Question