Solved

Remove all non-ascii characters from script with sed

Posted on 2012-03-19
5
371 Views
Last Modified: 2012-03-23
Hi,
I have some string and need to remove all non-ASCII characters with sed ot tr or awk:

echo "Here% is my st@^rin$g" | sed '???'

Checked s/[^[:ascii:]]//g or s/[^!-~\s]//g  - doesn't work

Thanks,
0
Comment
Question by:IKeystone
  • 3
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 37739933
all the characters in "Here% is my st@^rin$g"  are ASCII characters
0
 
LVL 84

Expert Comment

by:ozo
ID: 37739944
Did you mean you want to remove punctuation?

echo 'Here% is my st@^rin$g' | sed 's/[[:punct:]]//g'
0
 

Author Comment

by:IKeystone
ID: 37739965
Remove characters  from 128 to 255 and also 33,36,38,60,62 and may be some others.
0
 

Author Comment

by:IKeystone
ID: 37739976
Hi Ozo,
You solution working just fine. How to remove also all extended characters from  128 to 255 if they exist in string?
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 37739991
do you mean
sed 's/[^[:print:]]//g'
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question