- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to get rid of the empty string or unprintable ...
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
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
тАО06-15-2004 05:52 AM - last edited on тАО05-28-2012 02:14 AM by Ajay-Kumar
тАО06-15-2004 05:52 AM - last edited on тАО05-28-2012 02:14 AM by Ajay-Kumar
I have a string $xyz, and the valume of that is "HP-UX". I believe there are some either null strings or unprintable characters, how do I get rid of these null strings or unpritable characters?
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-15-2004 05:58 AM
тАО06-15-2004 05:58 AM
Re: how to get rid of the empty string or unprintable characters?
or
xyz=""
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-15-2004 06:05 AM
тАО06-15-2004 06:05 AM
Re: how to get rid of the empty string or unprintable characters?
You misunderstood my question.
The xyz variable includes the value of "HP-UX", and also some null or unpritable characters, I want to get rid of these characters, and just leave exactly "HP-UX".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-15-2004 06:24 AM
тАО06-15-2004 06:24 AM
Solution# echo $xyz | od -bc
0000000 H P - U X 001 \n
110 120 055 125 130 001 012
0000007
# xyz=`echo $xyz|tr -cd "A-Za-z-"`
# echo $xyz | od -bc
0000000 H P - U X \n
110 120 055 125 130 012
0000006
#
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-15-2004 06:34 AM
тАО06-15-2004 06:34 AM
Re: how to get rid of the empty string or unprintable characters?
You could do something like this
xyz=$(echo $xyz |strings|sed 's/[ ]*//g')
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-15-2004 06:49 AM
тАО06-15-2004 06:49 AM
Re: how to get rid of the empty string or unprintable characters?
newvar=`echo $var | tr -cd "-a-zA-Z0-9"`
this deletes all characters in the strings except the ones you specify. See the manpage to understand the options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-15-2004 06:53 AM
тАО06-15-2004 06:53 AM
Re: how to get rid of the empty string or unprintable characters?
echo $var|cut -c1-4
Anil
- Tags:
- cut
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-18-2004 10:58 PM
тАО06-18-2004 10:58 PM
Re: how to get rid of the empty string or unprintable characters?
We can remove the emtry stirngs using [:blank:] class and unprintable stirngs by [^:print:] (negatation of printable characters) To know more about this go to regexp man page on character class
xyz="HP-UX"
new_xyz=$(echo $xyz | tr -d "[:blank:][^:print:]")
There is a change in the old tr setup as
var="HP-UX"
new=`echo $var | tr -cd "\-a-zA-Z0-9"`
Use delimiter,because it will take as an option of tr.
Regards,
Muthukumar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2004 11:46 PM
тАО06-21-2004 11:46 PM
Re: how to get rid of the empty string or unprintable characters?
To remove the control char's as like \n we have to use [[:cntrl:]] regexp class. We can remove it easily as
xy="HP-UX^X"
# echo $xyz | tr -d "[[:blank:]][[^:print:]][[:cntrl:]]"| od -bc
0000000 H P - U X A
110 120 055 125 130 101
0000006
Regards,
Muthukumar.