- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: help- awk
Operating System - HP-UX
1752509
Members
4919
Online
108788
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
04-29-2009 10:16 PM
04-29-2009 10:16 PM
Hi,
I want to check a date format using awk. The input will be in the format 20090430.How do i check if this date given is valid?Im left with no clues on the checks using awk.
I want to check a date format using awk. The input will be in the format 20090430.How do i check if this date given is valid?Im left with no clues on the checks using awk.
Solved! Go to Solution.
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2009 10:55 PM
04-29-2009 10:55 PM
Solution
Starting with YYYYMMDD, you can split into 3 fields:
echo 20090430 | awk '
{
year = substr($0, 1, 4)
month = substr($0, 5, 2)
day = substr($0, 7, 2)
print "year=" year, "month=" month, "day=" day
shell_command = "echo $(cal " month " " year ")"
shell_command | getline
close(shell_command)
last_day = $NF
print "The last day in", year, month, "is", last_day
}
'
Once you have the fields, you can do the range checking and let cal(1) do the the days in each month and leap year checking.
echo 20090430 | awk '
{
year = substr($0, 1, 4)
month = substr($0, 5, 2)
day = substr($0, 7, 2)
print "year=" year, "month=" month, "day=" day
shell_command = "echo $(cal " month " " year ")"
shell_command | getline
close(shell_command)
last_day = $NF
print "The last day in", year, month, "is", last_day
}
'
Once you have the fields, you can do the range checking and let cal(1) do the the days in each month and leap year checking.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP