- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Replace leading zero with a space
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
Discussions
Discussions
Discussions
Forums
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
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
тАО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
- 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
- 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
- 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
- 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
- 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
- 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
- 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