awk help

Hi Guys,

I am trying to print all the filenames whose created/modified date is not today.

ts $ ls -lt
total 256
-rw-r--r--   1 fcfmetl  fastcar      116686 Sep 25 06:06 Output_execTVGen.txt
drwxr-xr-x   2 fcfmetl  fastcar         256 Sep 25 05:04 log
-rwxr-xr-x   1 fcfmetl  fastcar        2629 Sep 25 03:03 compass.sh
drwxr-xr-x   2 fcfmetl  fastcar         256 Sep 25 03:00 ftp
-rwxrwxrwx   1 fcfmetl  fastcar        3810 Sep 25 02:48 trigger_execTVGen.ksh
-rw-r--r--   1 fcfmetl  fastcar          88 Sep 24 09:57 email_body.txt
drwxr-xr-x   2 fcfmetl  fastcar         256 Sep 24 09:37 bckup

I am using the below command for it

ls -tl | awk -v f=`date '+%d'` '{if ("$7" -ne "$f" ){print $9}}'

But it is giving all the file name.

Can you let me know where i am going wrong.

Magesh

Try this solution :wink:

ls -lt | awk -v f=`date '+%d'` '$7 != f && $9{print $9}'
ls -l  | grep "$(date +"%b %d")" | awk '{ print $9 }'

Did you check the OP requirement ?

ls -tl | awk -v d=$(date +%d) -v m=$(date +%b) '$6 != d || $7 != m || $8!~/:/'

Jean-Pierre.

You can also use find for that.

 find . * -maxdepth 0 -atime +1

This commands doesn't give the required result.

Replacing -atime +1 by -atime +0 will not give the right result, because find works with hours*24.
A file created yesterday but less than 24 hours ago will not be selected.

Jean-Pierre.

Danmaro, Your solution worked fine expect that i have to replace awk wiht nawk..

Aigles, your solution is still giving me everything in the folder including the file created today..

log>ls -tl | nawk -v d=$(date +%d) -v m=$(date +%b) '$6 != d || $7 != m || $8!~/:/'
total 4
-rw-r-----   1 dsdev    dstage         0 Sep 25 08:23 b.txt
-rw-r-----   1 dsdev    dstage         0 Sep 25 08:23 a.txt
-rw-r-----   1 dsdev    dstage       584 Sep 15 06:06 pra.txt
-rw-r-----   1 dsdev    dstage        42 Sep 15 05:57 name.txyt

Thanks for your help..

Can you guys, point out what went wrong in my code?

On my system, the language is set to french, so the format of the date in the output is different (day and month are inverted).
Try:

ls -tl | awk -v d=$(date +%d) -v m=$(date +%b) '$7 != d || $6 != m || $8!~/:/'

Jean-Pierre.

Ohh.. my language is english (en). My OS is SunOs.. so, i dont know whether that is also causing a problem..

Can you point out the error in my code

Thanks

ls -lt | nawk 'd!=$6$7||$8!~/:/' d=$(date +%b%d)