Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Remove all non-ascii characters from script with sed

Posted on 2012-03-19
5
375 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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