- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: regular expressions sed and awk
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
04-15-2005 03:56 AM
04-15-2005 03:56 AM
So this string:
Hill, "Lefty" Brad (and company)
Becomes:
Hill Lefty Brad and company
No need to worry about other white space, there aren't any tabs etc.
I want to keep: A-Za-z0-9
and the space (decimal 32) and the rest can go.
Any way of doing this without explicitly naming 'the rest'?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2005 05:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2005 05:48 AM
04-15-2005 05:48 AM
Re: regular expressions sed and awk
nice, but if you must do it in sed, here is how you do
it:
str1='Hi, "Lefty" Brad (and company)'
str2=$(echo $str1 | sed 's/[A-Za-z0-9 ]//g')
str3=$(echo $str1 | sed "s/[$str2]//g")
echo $str3
You could read str1 from your input file directly.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2005 05:52 AM
04-15-2005 05:52 AM
Re: regular expressions sed and awk
str1='Hi, "Lefty" Brad (and company)'
echo $(echo $str1 | sed "s/[$(echo $str1 | sed 's/[A-Za-z0-9 ]//g')]//g")
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2005 06:43 AM
04-15-2005 06:43 AM
Re: regular expressions sed and awk
However, the command appears to also remove the carriage return at the end of the string.
How can that be prevented?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2005 06:56 AM
04-15-2005 06:56 AM
Re: regular expressions sed and awk
lt09:/home/merijn 122 > cat xx.txt
Hill, "Lefty" Brad (and company)
lt09:/home/merijn 123 > tr -c -d '[A-Za-z0-9 ]' < xx.txt
Hill Lefty Brad and companylt09:/home/merijn 124 > tr -c -d '[A-Za-z0-9 \n]' < xx.txt
Hill Lefty Brad and company
lt09:/home/merijn 125 >
Is perl an option too?
lt09:/home/merijn 126 > perl -ple's/[^\w ]+//g' < xx.txt
Hill Lefty Brad and company
lt09:/home/merijn 127 >
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2005 06:58 AM
04-15-2005 06:58 AM