- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- String manipulation: How to replace all n consecut...
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-04-2017 02:47 AM
тАО05-04-2017 02:47 AM
Hi All,
Here is a list of strings.
CONFOTA______ora___________________________________.aud
CONFOTA_____cjq_________.trc
CONFOTA__dbrm_________.trc
CONFOTA___lgwr_________.trc
How to replace all n consecutive "_" characters by only one "_" to obtain the result as below ?:
CONFOTA_ora_.aud
CONFOTA_cjq_.trc
CONFOTA_dbrm_.trc
CONFOTA_lgwr_.trc
Thanks in advance for your apprciated help,
Kind regards,
Den.
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2017 05:15 AM
тАО05-04-2017 05:15 AM
Solution> How to replace all n consecutive "_" characters by only one "_" to
> obtain the result as below ?:
mba$ echo 'CONFOTA_____cjq_________.trc' | sed -e 's/__*/_/g'
CONFOTA_cjq_.trc
For one "_" followed by any number (0, 1, 2, ...) of "_" ("_*"),
substitute one "_", and repeat for all non-overlapping matches ("g").
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2017 12:40 PM
тАО05-04-2017 12:40 PM
Re: String manipulation: How to replace all n consecutive "_" characters by only one "
Another solution is to use tr like this:
echo 'CONFOTA_____cjq_________.trc' | tr -s '_'
-s option will replace two or more consecutive occurrences of the specified character with a single instance of that character.
Bill Hassell, sysadmin