- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to capture last 2 digits/chars of variable
Operating System - HP-UX
1756432
Members
2869
Online
108847
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
Go to solution
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
тАО05-11-2005 06:26 AM
тАО05-11-2005 06:26 AM
Re: how to capture last 2 digits/chars of variable
Here's one more that uses only shell internal commands.
$ x="abcdefg"
$ typeset -R2 y=$x
$ echo $y
fg
"typeset" is an internal command to the shell, so no external processes are run.
HTH
-- Rod Hills
$ x="abcdefg"
$ typeset -R2 y=$x
$ echo $y
fg
"typeset" is an internal command to the shell, so no external processes are run.
HTH
-- Rod Hills
There be dragons...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2005 06:49 AM
тАО05-11-2005 06:49 AM
Re: how to capture last 2 digits/chars of variable
Could you explain the last assignment...what does the #$x do?
from procura's cut and paste,
x=${var%??}
This removes the smallest suffix from the variable that matches the pattern. The pattern is this case is ??. ? matches any character. So, this removes the last two characters from var.
last2char=${var#$x}
this removes the smallest prefix pattern from the variable. From above, $x is everything but the last two characters. So, this removes everything from the front of var except the last two characters. Which leaves you with just the last two characters that your looking to get.
from procura's cut and paste,
x=${var%??}
This removes the smallest suffix from the variable that matches the pattern. The pattern is this case is ??. ? matches any character. So, this removes the last two characters from var.
last2char=${var#$x}
this removes the smallest prefix pattern from the variable. From above, $x is everything but the last two characters. So, this removes everything from the front of var except the last two characters. Which leaves you with just the last two characters that your looking to get.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2005 05:26 PM
тАО05-11-2005 05:26 PM
Re: how to capture last 2 digits/chars of variable
Let's try to get "anip" from the string "manipulate"
#!/bin/sh
s="manipulate"
s1=`expr substr $s 2 4`
echo $s1
-----------------------
echo "manipulate" | cut -b 2-5
------------------------
s=manipulate
echo $s | awk '{print substr($0,2,4)}'
-------------------------
Good Luck,
#!/bin/sh
s="manipulate"
s1=`expr substr $s 2 4`
echo $s1
-----------------------
echo "manipulate" | cut -b 2-5
------------------------
s=manipulate
echo $s | awk '{print substr($0,2,4)}'
-------------------------
Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2005 06:34 PM
тАО05-11-2005 06:34 PM
Re: how to capture last 2 digits/chars of variable
I prefer Rodney Hill's solution:
typeset -R2
typeset -R2
- « Previous
-
- 1
- 2
- Next »
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