- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to put space in a variable in unix ?
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
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
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
тАО06-03-2010 10:04 AM
тАО06-03-2010 10:04 AM
How can I put spaces using tr or perl/or other unix command ?
Thanks
#!/bin/ksh
###++++++++++++test script ##
MONTH=`date +"%b`
DAY=`date +"%d`
FIRST_CHAR=`echo $DAY|cut -c1`
if [ $FIRST_CHAR = "0" ];then
DAY=`echo $DAY|tr -s '0' ' '`
fi
DATE="$MONTH $DAY"
echo $DATE
###++++++++++++
# ./test
Jun 3
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2010 10:13 AM
тАО06-03-2010 10:13 AM
Re: How to put space in a variable in unix ?
DAY=`echo $DAY|tr -s '0' ' '`
use:
echo ${DAY/0/}
and that will remove the offending '0'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2010 10:17 AM
тАО06-03-2010 10:17 AM
Re: How to put space in a variable in unix ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2010 10:57 AM
тАО06-03-2010 10:57 AM
Re: How to put space in a variable in unix ?
DAY=`echo $DAY | sed -e 's/0/ /g'`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2010 11:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2010 11:21 AM
тАО06-03-2010 11:21 AM
Re: How to put space in a variable in unix ?
Verify it by puting this after the "fi"
echo ":$DAY:"
You will see that $DAY is formatted correctly. The fix is provided by Matti.
Now you can replace the entire shell program with these two lines
DATE=`date +"%b %e"
echo "$DATE"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2010 11:27 AM
тАО06-03-2010 11:27 AM
Re: How to put space in a variable in unix ?
I believe Tingli solutionn would work too but double quotes is simpler.
Thanks to all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2010 11:38 AM
тАО06-03-2010 11:38 AM
Re: How to put space in a variable in unix ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2010 02:51 PM
тАО06-03-2010 02:51 PM
Re: How to put space in a variable in unix ?
would become...
$> echo ${DAY/0/X}|tr X " "
3
and it works!
a little too late though ... :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2010 07:17 AM
тАО06-04-2010 07:17 AM
Re: How to put space in a variable in unix ?
John J - I will keep your command in my notes and will come in handy.
Thanks so much