UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old January 4th, 2005, 08:32 PM
justapackfan justapackfan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 2 justapackfan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sed question, given a set of char's, replace char's not in the set

Hello, and thanks for taking time to read my question.
I would like to use sed, or "tr", to replace any invalid character with a <space>. My set of valid characters are
a-z A-Z 0-9 ! " & , ( ) + ' ? = @ / . -

If the line contains any characters not in the set listed above, I would like to replace each invalid one with a <space>.

My attempt at this is:
sed 's/[^a-zA-Z0-9!"&,()+\`?=\@;\/\.-]/ /g'
but this will not quite do it. It does not do a one for one replace of bad characters.

thank you for any advice

Reply With Quote
  #2  
Old January 4th, 2005, 09:56 PM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
It seems to work for me...
Code:
$ echo 'a((:::c%%b' | sed 's/[^a-zA-Z0-9!"&,()+\`?=\@;\/\.-]/ /g'
a((   c  b
$

Reply With Quote
  #3  
Old January 5th, 2005, 05:13 PM
justapackfan justapackfan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 2 justapackfan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Thanks Perderabo, it is working :)

I'm not sure why it wasn't before, but I copied and pasted your exact text and it does work. This is my first attempt at using SED and I'm finding it a bit tricky to get the syntax down. Thank You for the assistance, much appreciated.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > sed question, given a set of char's, replace char's not in the set


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway