| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
comparing dates from a file
|
Original Message
|
Name: Ashoke Bhowmick
Date: September 27, 2002 at 04:08:19 Pacific
Subject: comparing dates from a file OS: Unix CPU/Ram: 5.2
|
Comment: Hi , I am new to Unix environment.I have a generated file containing the contents of a directory. The file (dir.txt) is something like following. 08-19-02 04:42PM 443463691 jul02.zip 08-20-02 02:22PM 443463691 jul02new.zip Please guide me in writing a shell script that will read the file(dir.txt) and identify which file (jul02.zip etc) is the latest one and do some processing accordingly. Thanks in advance and regards, Ashoke Bhowmick
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: David Perry
Date: September 27, 2002 at 04:55:54 Pacific
|
Reply: (edit)ls has a parameter to sort by date. Try ls -last dir/* otherwise you can use awk and cut to pull fields for comparison year=`head -1 dir.txt | cut -f 3 -d '-' | awk '{print $1}'`
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Ashoke Bhowmick
Date: September 27, 2002 at 05:05:48 Pacific
|
Reply: (edit)Hi , Thanks for quick reply. I won't be able to use the "ls -last dir/*" command, since the file is generated by doing an FTP to a remote server and listing the files using ls command. The FTP protocol doesn't have powerful set of commands.I am not sure whether there is an equivalent command for FTP to sort files according to date. I don't have a telnet access to that remote server. I would try out the second option suggested by you.
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Unix Forum Home