- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to remove leading and trailing spaces from...
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
тАО05-21-2009 04:39 AM
тАО05-21-2009 04:39 AM
I have to remove heading and trailing spaces from string.
Name=" Mark Barnatsom "
I want out put as:
Mark Barnatson.
Can some one help me to do this?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 04:50 AM
тАО05-21-2009 04:50 AM
Re: how to remove leading and trailing spaces from string?
TrimmedName=`echo ${Name}|sed -e "1,1s/^ //" | sed -e "1,1s/ $//"`
To show the effects
echo "##"${Name}"##"; echo "##"${TrimmedName}"##"
I am sure there is a craftier solution using PERL or awk, but this is what I could come up with at the moment.
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 04:55 AM
тАО05-21-2009 04:55 AM
Re: how to remove leading and trailing spaces from string?
Another way is with Perl. This will handle spaces and/or tab characters:
# echo ${Name}|perl -ple 's/^\s*//;s/\s*$//'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 05:01 AM
тАО05-21-2009 05:01 AM
Re: how to remove leading and trailing spaces from string?
bash$ x=` echo ' a b c ' | sed -e 's/^ *//' -e 's/ *$//' `
bash$ echo ">$x<"
>a b c<
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 05:09 AM
тАО05-21-2009 05:09 AM
Re: how to remove leading and trailing spaces from string?
#echo "string" |cut -c
Examble:
# echo "Name=" Mark Barnatsom "" |cut -c 7-21
Mark Barnatsom
#
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 06:27 AM
тАО05-21-2009 06:27 AM
Re: how to remove leading and trailing spaces from string?
NAME=${NAME## }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 07:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 06:40 PM
тАО05-21-2009 06:40 PM
Re: how to remove leading and trailing spaces from string?
> [...]
Easy, but it doesn't do what was requested
("remove leading and trailing spaces").
bash$ x=` echo ' a b c ' | sed -e 's/^ *//' -e 's/ *$//' `
bash$ echo ">$x<"
>a b c<
bash$ NAME=' a b c '
bash$ echo ">$(echo $NAME)<"
>a b c<
Now, if you _want_ to reduce the interior
white space to single spaces, that's fine,
but it's not what was requested.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 10:03 PM
тАО05-21-2009 10:03 PM
Re: how to remove leading and trailing spaces from string?
All are correct but i used Tinqli second answer and James answer.
Thank you very much for giving your valuable time.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2009 12:34 AM
тАО05-22-2009 12:34 AM
Re: how to remove leading and trailing spaces from string?
If your field saperator is " then you can use this also
awk -F"\"" '{ print $1 }'
Suraj