I have a list of accepted characters:


These characters can be translated in the ASCII decimal range 33-73

The implementation I'd like would parse the lines of an input file, detecting any character out of this range, and returning the corresponding line.

grep -E '[^33-73]{1,}'

where -E is for regex interpretation, ^ is for matching any characters NOT in the list, {1,}is for matching one or more occurrences... and [33-73] is a way to symbolize the wanted range of characters in decimal format, I don't know how to express this in a way it's interpretable by grep.

(I could define the list of characters in the regex itself, but escaping of reserved grep -E characters makes the expression hard to read.)

Is there a way to implement this in grep? (FYI trying to make it work on (BSD grep) 2.5.1-FreeBSD)

Example input:

$ cat f1.txt

Expected output:


1 Answer 1


Since these are consecutive characters in ASCII, you should be able to simply do:

$ grep '[^!-I]' file

Or, safer in case you have a different locale:

$ LC_ALL=C grep '[^!-I]' file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .