- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: How to extract char from string in $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
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-01-2006 06:34 PM
тАО05-01-2006 06:34 PM
How do i extract certain characters from a string stored in a $variable?
For example:
set text = "01L"
i want to extract and store "01" only into another $variable. Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2006 06:44 PM
- Tags:
- cut
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2006 06:47 PM
тАО05-01-2006 06:47 PM
Re: How to extract char from string in $variable?
export variable="01L"
var1=`echo $variable|cut -c 1,2`
echo $var1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2006 06:58 PM
тАО05-01-2006 06:58 PM
Re: How to extract char from string in $variable?
I've got it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2006 07:14 PM
тАО05-01-2006 07:14 PM
Re: How to extract char from string in $variable?
http://www.google.com/url?sa=t&ct=res&cd=2&url=http%3A%2F%2Fwww.dreamsyssoft.com%2Funix-shell-scripting%2Fadvanced-tutorial.php&ei=ef5WRJHWI7_SwgHy1OT5Bw&sig2=IZ1E-i7ZUt4wAbup0PpOR
http://www.google.com/url?sa=t&ct=res&cd=1&url=http%3A%2F%2Fwww.cactus.org%2F~dak%2Fshellscript.html&ei=ef5WRJHWI7_SwgHy1OT5Bw&sig2=KsUK1AlA6rlf7qHRH5ZgvQ
Perhaps these links will help.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2006 11:41 PM
тАО05-01-2006 11:41 PM
Re: How to extract char from string in $variable?
Andrew,
I'm glad you found a solution.
However, it involves a fork of a utility where it seems that a native shell command can do the trick.
For onesies-twosies it does not matter, for commands executed in a tight loop it can make a critical difference in execution performance.
The shell has several editing operations.
In your case i woudl consider 'tail end pattern deletion'
For example:
# text="01L"
# other=${text%[A-Z]}
# echo $other
01
from "man ksh"
:
${parameter%pattern}
:
If the shell pattern matches the end of the value of parameter, the value of parameter with the matched part is deleted; otherwise substitute the value of parameter. In the former, the smallest matching pattern is deleted; in the latter, the largest matching pattern is deleted.
hth,
Hein.
- Tags:
- variable