HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- cut the last few character(s) in a word
Operating System - Linux
1832350
Members
2636
Online
110041
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
Forums
Discussions
Discussions
Discussions
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
12-17-2005 03:05 AM
12-17-2005 03:05 AM
cut the last few character(s) in a word
Hi
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
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
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2005 03:16 AM
12-17-2005 03:16 AM
Re: cut the last few character(s) in a word
Hi,
you can use tr utility:
ex:
echo sclk_ap3 | tr -d [:digit:]
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-18-2005 06:55 AM
12-18-2005 06:55 AM
Re: cut the last few character(s) in a word
Is the input all on one line?
Always comma seperated?
If you just want those numbers, then you could delete anything else using tr -d.
For example:
$ cat x
clap1,scl_ap2,sclk_ap3,...sclok_ap20
$ cat x | tr -d "_a-z"
1,2,3,...20
Same thing using perl, where you can use samrter regexpr as needed (not used here):
$perl -pe 's/[_a-z]*//g' x
Often I find i need a bit more logic and would prefer to deal with each line and each 'word'. In perl that could look like:
$ perl -ne 'foreach $word(split /,/)
{ $word =~ s/^(\D*)//; print "$word\n"}' x
1
2
3
20
The -ne is an implied loop over the input lines reading into $_
The foreach loops through the result of a split on the default $_ assigning to $word
The block first performs a subsitute on $word, then prints.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2005 04:21 PM
12-18-2005 04:21 PM
Re: cut the last few character(s) in a word
You can try like,
# cat file
sclap1
scl_ap2
sclk_ap3
sclok_ap20
# sed 's/^.*\([a-z][a-z].*\)/\1/' file
ap1
ap2
ap3
ap20
-Muthu
# cat file
sclap1
scl_ap2
sclk_ap3
sclok_ap20
# sed 's/^.*\([a-z][a-z].*\)/\1/' file
ap1
ap2
ap3
ap20
-Muthu
Easy to suggest when don't know about the problem!
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.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP