Solved

Remove all non-ascii characters from script with sed

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
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…
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

11 Experts available now in Live!

Get 1:1 Help Now