- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Cut the last character(s) from a word
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
12-17-2005 03:08 AM
12-17-2005 03:08 AM
Anybody know how to cut last few character(s)
from a word.
I have sclap1,scl_ap2,sclk_ap3...sclok_ap20. and want to cut 1,2...20. or atleast ap1,ap2,....ap20
Thanks
Sajeesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2005 03:18 AM
12-17-2005 03:18 AM
Re: Cut the last character(s) from a word
you can use tr utility:
ex:
echo sclk_ap3 | tr -d [:digit:]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2005 03:59 AM
12-17-2005 03:59 AM
Re: Cut the last character(s) from a word
You can use awk:
awk '{printt substr($0,1,length($0)-N)}' N=3 file
You can chnge N as you need
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2005 04:17 AM
12-17-2005 04:17 AM
Re: Cut the last character(s) from a word
# echo sclok_ap20|sed 's/[0-9]\{1,\}//g'
This will remove any number of digits. If you want to specify a range of digits, as for example only 2-3 digits, but not one or more than four:
# sclok_ap20|sed 's/[0-9]\{2,3\}//g'
In general, {m,n} specifies the minimum number and the maximum number. If 'n' is omitted, as in the first example, then the maximum is unlimited.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2005 04:28 AM
12-17-2005 04:28 AM
Re: Cut the last character(s) from a word
Actually I want to capture the digit from these words, not to exclude. It will be either 1 digit or 2 digit.
I have to use these captured number within a for loop
Regards
Sajeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2005 04:48 AM
12-17-2005 04:48 AM
Re: Cut the last character(s) from a word
OK, then let's use perl:
# echo sclok_ap20|perl -nle 'm/(\d+)/;print $1'
...prints 20
This extracts one or more digits.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2005 05:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2005 02:57 PM
12-17-2005 02:57 PM
Re: Cut the last character(s) from a word
Thanks to you all. Not familer with the perl, so used the last one.
Thanks
Sajeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2005 09:19 PM
12-18-2005 09:19 PM
Re: Cut the last character(s) from a word
to obtain only teh difit:
echo "sclap1 scl_ap2 sclk_ap3 sclok_ap20"|tr -d [:alpha:][:punct:]
It ill retrun aonly the difit in teh strings.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2005 09:23 PM
12-18-2005 09:23 PM
Re: Cut the last character(s) from a word
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=984492
Do you want to get digits only then,
simpy then,
# cat file
sclap1
scl_ap2
sclk_ap3
sclok_ap20
# sed 's/^[^0-9]*//' file
1
2
3
20
# for i in `sed 's/^[^0-9]*//' file`
> do
> echo $i
> done
-Muthu