Solved

Remove all non-ascii characters from script with sed

Posted on 2012-03-19
5
366 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
Comment Utility
all the characters in "Here% is my st@^rin$g"  are ASCII characters
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Did you mean you want to remove punctuation?

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

Author Comment

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

Author Comment

by:IKeystone
Comment Utility
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
Comment Utility
do you mean
sed 's/[^[:print:]]//g'
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now