Home » Infrastructure » Unix » how to extract date from ls -al
how to extract date from ls -al [message #98416] Wed, 22 September 2004 08:25 Go to next message
Arun Peter
Messages: 1
Registered: September 2004
Junior Member
I have file in unix like this one

ls -al

-rw-r--r--   1 apeter      dev         9 Sep 22 12:25 test

I want to extract the date portion (Sep 22) for some checking. I have used

ls -al test | cut -f6,7 -d' '

 

It doesn't seems to work.

 

How do I extract the date portion out. I am not very familiar with awk utility. Can someone help?

 

 

 

 
Re: how to extract date from ls -al [message #98417 is a reply to message #98416] Wed, 22 September 2004 08:43 Go to previous messageGo to next message
Anu
Messages: 82
Registered: May 2000
Member
ls -lrt test | awk '{print $5 $6 $7 $8}'

By the way do not use the file name as test, as its reserved word.

Cheers
Annnu
Re: how to extract date from ls -al [message #98423 is a reply to message #98417] Mon, 27 September 2004 18:47 Go to previous message
Jai Vrat Singh
Messages: 205
Registered: September 2002
Location: Singapore
Senior Member
Better to use, because different systems have different settigs, but starting from last 4 , each has the dates and filenames.
ls -lrt myfile  | sed -f sed.file | awk -F'|' '{ printf("%s %s %sn",$(NF -3), $(NF -2), $(NF -1) ); }'


where sed.file
contains
 s/[     ][      ]*/&#124/g


The [[ ]] contains a space and a tab.
Previous Topic: Core dump (Please reply ASAP)
Next Topic: where can download "Oracle Universal Installer" software alone?
Goto Forum:
  


Current Time: Fri Nov 29 09:18:32 CST 2024