- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- remove extra spaces in a string
Operating System - HP-UX
1752337
Members
5641
Online
108787
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
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
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
тАО03-07-2008 10:26 PM
тАО03-07-2008 10:26 PM
remove extra spaces in a string
Hello,
i want to remove extra spaces in my string in unix. which command i need to use.
Ex: i am rahul. this is the string now i want the result to be as : i am rahul
i want to remove extra spaces in my string in unix. which command i need to use.
Ex: i am rahul. this is the string now i want the result to be as : i am rahul
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2008 11:10 PM
тАО03-07-2008 11:10 PM
Re: remove extra spaces in a string
hi,
it seems that you already have a similar thread at:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1210930
please check and let us know if the solutions provided are helpful.
Otherwise, clarify your question further.
kind regards
yogeeraj
it seems that you already have a similar thread at:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1210930
please check and let us know if the solutions provided are helpful.
Otherwise, clarify your question further.
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-08-2008 09:46 AM
тАО03-08-2008 09:46 AM
Re: remove extra spaces in a string
manasa,
Where is the string coming from / going to?
Is it in a file? a shell variable? what shell?
What problem are you really trying to solve?
The answer to that question will help define the optimal answer to the part question you asked.
If you choose to explain the problem better be sure to click 'Retain format(spacing). URLs will not be clickable' because as you see, the itrc forum mangled your entrie to loose teh cirtical example. In addition you may want to attach a .txt file with EXACT input examples and EXACT desired output.
Anyway...
If it is in a shell variable then just a simple print will 'clean it up' and we can use that:
$ x='aap noot mies'
$ print "$x"
aap noot mies
$ print $x
aap noot mies
$ y=$(print $x)
$ print "x:$x.y:$y"
x:aap noot mies.y:aap noot mies
$
Or you can feed it to 'sed'
For example:
$ y=$(print "$x" | sed 's/ */*/g')
$ print "$y"
aap*noot*mies
So the RE (regular expression) is to match a space, followed by zero or more spaces.
To be replaced in the example by *, but a space for you.
spaces or white-space (tabs also)?
Good luck,
Hein.
Where is the string coming from / going to?
Is it in a file? a shell variable? what shell?
What problem are you really trying to solve?
The answer to that question will help define the optimal answer to the part question you asked.
If you choose to explain the problem better be sure to click 'Retain format(spacing). URLs will not be clickable' because as you see, the itrc forum mangled your entrie to loose teh cirtical example. In addition you may want to attach a .txt file with EXACT input examples and EXACT desired output.
Anyway...
If it is in a shell variable then just a simple print will 'clean it up' and we can use that:
$ x='aap noot mies'
$ print "$x"
aap noot mies
$ print $x
aap noot mies
$ y=$(print $x)
$ print "x:$x.y:$y"
x:aap noot mies.y:aap noot mies
$
Or you can feed it to 'sed'
For example:
$ y=$(print "$x" | sed 's/ */*/g')
$ print "$y"
aap*noot*mies
So the RE (regular expression) is to match a space, followed by zero or more spaces.
To be replaced in the example by *, but a space for you.
spaces or white-space (tabs also)?
Good luck,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2008 12:21 AM
тАО03-10-2008 12:21 AM
Re: remove extra spaces in a string
Hi,
tr -d " "
will remove all spaces in the string.
The use depends where you have your string: var, file, etc.
HTH,
Art
tr -d " "
will remove all spaces in the string.
The use depends where you have your string: var, file, etc.
HTH,
Art
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