- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to compare dates in a text file ?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 03:21 AM
05-27-2002 03:21 AM
I have a text file containing tape barcode labels and the date they expire. Typically looks like this :
Barcode: 000001 Expire Date: Wed Mar 28 2001
Barcode: 000001 Expire Date: Thu May 16 2002
I'm writing a script which searches this text file and identifies all tapes which have expired. To do this I need a way of taking the sysdate, comparing it with the dates in the file and identifying all dates prior to the sysdate. Is there a way of doing this?
Many thanks and regards,
Preet :-)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 03:50 AM
05-27-2002 03:50 AM
Solutionhere an awk script for you:
awk -vcday=$(date +%d) -vcmon=$(date +%m) -vcyear=$(date +%Y) '{
day=$(NF-1)
if($(NF-2)=="Jan") mon=1
if($(NF-2)=="Feb") mon=2
if($(NF-2)=="Mar") mon=3
if($(NF-2)=="Apr") mon=4
if($(NF-2)=="May") mon=5
if($(NF-2)=="Jun") mon=6
if($(NF-2)=="Jul") mon=7
if($(NF-2)=="Aug") mon=8
if($(NF-2)=="Sep") mon=9
if($(NF-2)=="Oct") mon=10
if($(NF-2)=="Nov") mon=11
if($(NF-2)=="Dec") mon=12
year=$(NF)
expire="No"
if(year < cyear)
expire="Yes"
else if(year == cyear)
{
if(mon < cmon)
expire="Yes"
else if(mon == cmon)
{
if(day < cday)
expire="Yes"
}
}
print $0 ": Expire = " expire
}'
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 03:54 AM
05-27-2002 03:54 AM
Re: How to compare dates in a text file ?
This should be fairly straightforward...
Get today's date in the format yyyymmdd:
TODAY=$(date +%Y%m%d)
Then for each record in your file, convert the date to the same format then compare them:
cat
while read X TAPE X X X MM DD YYYY
# convert Month in MM to numeric
do
case ${MM} in
Jan) M=01;;
Feb) M=02;;
Mar) M=03;;
Apr) M=04;;
May) M=05;;
Jun) M=06;;
Jul) M=07;;
Aug) M=08;;
Sep) M=09;;
Oct) M=10;;
Nov) M=11;;
Dec) M=12;
esac
let YYYYMMDD=$(YYYY}${MM}${DD}
if (( YYYYMMDD < TODAY }};
then
fi
done
}
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 03:56 AM
05-27-2002 03:56 AM
Re: How to compare dates in a text file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 06:54 AM
05-27-2002 06:54 AM
Re: How to compare dates in a text file ?
Many thanks for your help with this.
Just a quick question - is the following line correct :
if (( YYYYMMDD < TODAY }};
It looks like the open brackets (( and braces }} are not matched ?
Regards,
Preet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 07:38 AM
05-27-2002 07:38 AM
Re: How to compare dates in a text file ?
Best Regards,
Preet :-))