The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
search by modified date kotasateesh Shell Programming and Scripting 4 06-24-2008 06:59 AM
How to list files that were added or modified on a certain date? thoughts UNIX for Dummies Questions & Answers 8 02-19-2008 10:44 PM
greping certain modified date ali560045 Shell Programming and Scripting 2 02-08-2008 04:54 AM
Create a list of files that were modified after a given date. rkka UNIX for Dummies Questions & Answers 4 01-22-2008 02:12 AM
How do I get the last modified date of a file? akpopa UNIX for Dummies Questions & Answers 2 08-29-2001 12:08 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 06-27-2005
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,262
I don't know what OS you are on, but an easy and ALWAYS working way to get the last modification date is to do an "ls -l".

Having said this, the following line should give you the desired result for a file (replace "<space>" with literal spaces and <filename> with the filename):

Code:
ls -l <filename> | sed 's/<space><space>*/<space>/g' | cut -d'<space>' -f6,7
This should give something like "Apr 14" or "Jun 22". Look at the output of "ls -l". First, the sed-statement reduces multiple occurences of spaces to exactly one each. Then "cut" is used to get out the fields 6 and 7 (-f6,7) using spaces as delimiters between fields (-d'<space>'). I describe this in detail because it is a very common way of extracting data from tabular input, you may want to experiment with it a little to really understand how it works.

To put the extracted data into your HTML file you will need this plus some HTML-Tags surrounding it, namely "<TD>" and "</TD>". The following should do the trick:

Code:
chFileDate="$( ls -l <filename>                  |\
               sed 's/<space><space>*/<space>/g' |\
               cut -d'<space>' -f6,7              \
             )"
print - "<TD> $chFileDate </TD>" | tee -a $HTMLFILE
Hope this helps

bakunin
Reply With Quote
Forum Sponsor
  #9  
Old 06-27-2005
Registered User
 

Join Date: Jun 2005
Posts: 16
it doesnt work

Code:
modiDate = "$( ls -al $PFAD$DR | sed 's/ */ /g* | cut -d ' ' -f6,7)"
i have Hp-Unix System
Reply With Quote
  #10  
Old 06-27-2005
Registered User
 

Join Date: Jun 2005
Posts: 16
Yeah

I have solved this problem problem with
Code:
ls -al $PFAD$DR | awk '{printf("<TD>%s %s %s\n", $6, $7, $8)}' | tee -a $HTMLFILE
and now i need the german format of the date

it print's Feb 22 10:48

i want '17. Jan 2005'

how can i solve this one
Reply With Quote
  #11  
Old 06-27-2005
r2007's Avatar
Registered User
 

Join Date: Jun 2005
Location: China
Posts: 73
try
Code:
ls -l --time-style="long-iso"
or
ls -l --time-style="+%e,%b %Y"
It works on gentoo 1.4.
Reply With Quote
  #12  
Old 06-27-2005
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,262
Quote:
Originally Posted by cengiz
it doesnt work

Code:
modiDate = "$( ls -al $PFAD$DR | sed 's/ */ /g* | cut -d ' ' -f6,7)"
i have Hp-Unix System
It doesn't work, because you have written "cut -d ' '" instead of "cut -d' '", have forgotten a closing single quote on the sed-statement and put a (superfluous) asterisk there instead. On top you have replaced the two spaces in the matching string of the sed-script with one, which alters greatly what the script does. Instead of changing one or more spaces to exactly one space it changes zero or more spaces to exactly one space now.

Your awk solution is not really recommendable, because you call awk several times for every table row and perhaps nested in a loop to print several rows only to do a formatted print which can be done directly in the shell. Maybe your environment has enough unused computing power to allow for that, but in principle this is a waste of resources.

It may be that I'm old-fashioned, but I learned that a good solution is not one that works but one that works and is efficient and elegant. Computing power or any other resource should never be taken for granted and neither wasted if it could be conserved.

Ok, I'm already through ranting.....

bakunin

PS: to get the german Date switch your language environment to german oder "de_de". Having no HP-Ux-machine at hand i can point you only in the general direction, you should find this somewhere in the sam-menus in the user configuration.

bakunin
Reply With Quote
  #13  
Old 06-27-2005
Registered User
 

Join Date: Jun 2005
Posts: 16
@r2007
I've tried this but when i execute it he say --time-style="long-iso" not found an the second example, too.

@bakunin
thank you for your opinion. I try your solution and if it works i apply it on code.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0