- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Removing the last Character from a variable
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
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
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
01-14-2004 08:02 AM
01-14-2004 08:02 AM
VAR = foobar
needs to be
VAR = fooba
I need the "r" removed from foobar. The variable is never the same lenght. Thanks in advance.
Tommy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 08:13 AM
01-14-2004 08:13 AM
Re: Removing the last Character from a variable
One way is
VAR=$(echo $VAR |cut -c 1-$(echo "$(echo $VAR|wc -c)-2"|bs))
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 08:35 AM
01-14-2004 08:35 AM
Re: Removing the last Character from a variable
another way is:
VAR=`echo foobar | awk '{print substr($0,1,length($0)-1)}'`
VAR=`echo foobar|sed 's/.$//'`
VAR=`expr "foobar" : "\(.*\).$"`
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 09:25 AM
01-14-2004 09:25 AM
Re: Removing the last Character from a variable
var=`echo $x | sed -e 's/.$//'`
there may be a better/easier way but
heck, it works!
...Laurie :{)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 09:25 AM
01-14-2004 09:25 AM
Re: Removing the last Character from a variable
var=`echo $var | sed -e 's/.$//'`
there may be a better/easier way but
heck, it works!
...Laurie :{)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 10:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2004 07:23 PM
01-14-2004 07:23 PM
Re: Removing the last Character from a variable
Curt's approach is BY FAR the best solution in this thread and deserves the 10pts. All other approaches use subshells, pipes, external commands and thus cause thremendous fork/exec activity during execution.
We see often terrible performance problems on machines that are caused by terribly bad coded shell scripts. PLEASE try to use shell built-ins whenever this is possible.
OK, when the script is supposed to run rarely... no problem. :-)
Just my 2 cents...
Dietmar.