- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - HP-UX
- >
- Languages and Scripting
- >
- Re: Replace leading zero with a space
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Email to a Friend
- Report Inappropriate Content
11-20-2007 02:07 AM
11-20-2007 02:07 AM
MON=`date +%b`
DAY=`date +%d`
HOUR=`date +%H`
EXT1=`echo ${MON} ${DAY} | tr "010203040506070809" " 1 2 3 4 5 6 7 8 9"`
This was working until today (Nov 20). Instead of getting "Nov 20", I get "Nov 2 ". I used the tr command to translate "Nov 01" to "Nov 1", etc. I use this script to extract data from the syslog.log which is in this format.
Solved! Go to Solution.
- Tags:
- date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-20-2007 02:26 AM
11-20-2007 02:26 AM
Re: Replace leading zero with a space
You will need to rework your matching.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-20-2007 02:27 AM
11-20-2007 02:27 AM
SolutionUse %e rather than %d for the day of the month.
Note that you should really do a single date command because you could execute this as 3 seprate commands and cross midnight so that you get a bogus date.
date '+%b %e %H' | read MON DAY HOUR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-20-2007 02:27 AM
11-20-2007 02:27 AM
Re: Replace leading zero with a space
Simply use:
# DAY=`date +%e`
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-20-2007 02:33 AM
11-20-2007 02:33 AM
Re: Replace leading zero with a space
perhaps something like:
DAY=` date +%d | sed -e 's/^0//' `
or:
DAY=` date +%e | sed -e 's/^ //' `
"tr" looks like the wrong tool for this job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-20-2007 02:36 AM
11-20-2007 02:36 AM
Re: Replace leading zero with a space
EXT1=$(date '+%b %e')
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-20-2007 02:39 AM
11-20-2007 02:39 AM
Re: Replace leading zero with a space
date '+%b %e %H' | read MON DAY HOUR
The '%e' outputs the day with a possible leading space but the read strips off the whitespace IFS (Input Field Separator) so that the day is left as "1" rather than " 1".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-20-2007 10:38 PM
11-20-2007 10:38 PM
Re: Replace leading zero with a space
To me it is better if all dates have the same number of character and don't special case any numbers. After all, you don't want to be like some European locales that actually have a space or remove it and be shorter.
- Tags:
- locale
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP