Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

Remove all non-ascii characters from script with sed

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
IKeystone
Asked:
IKeystone
  • 3
  • 2
1 Solution
 
ozoCommented:
all the characters in "Here% is my st@^rin$g"  are ASCII characters
0
 
ozoCommented:
Did you mean you want to remove punctuation?

echo 'Here% is my st@^rin$g' | sed 's/[[:punct:]]//g'
0
 
IKeystoneAuthor Commented:
Remove characters  from 128 to 255 and also 33,36,38,60,62 and may be some others.
0
 
IKeystoneAuthor Commented:
Hi Ozo,
You solution working just fine. How to remove also all extended characters from  128 to 255 if they exist in string?
0
 
ozoCommented:
do you mean
sed 's/[^[:print:]]//g'
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now