Grep - build character range with octal or hexa representation

Hello

I would like to make a character range like that :

echo "ABCDEF+1234" | grep -E '[\x26-\x40]'

or

echo "ABCDEF+1234" | grep -E '[\046-\100]'

or

echo "ABCDEF+1234" | grep -E '[&-@]'

Which should works on linux with english language
And works also on linux with french language ( english install and after add french )
On my second laptop ( french ) I got this error :

grep: end of interval invalid

but its works on my server (english)

Would this help?

echo "ABCDEF+1234" | grep -E "[\x26-\x40]"
grep: Invalid range end
echo "ABCDEF+1234" | LC_ALL=C grep -E "[\x26-\x40]"
ABCDEF+1234

---------- Post updated at 17:49 ---------- Previous update was at 17:40 ----------

And this would correctly produce the chars equivalent to the hex codes:

echo "ABCDEF+1234" | LC_ALL=C grep -E "["$'\x26'-$'\x40'"]"
+ grep -E '[&-@]'
ABCDEF+1234
1 Like

Is there a way to put some macro LC_ALL=C at the beginning of the script if language is not English and remove it before the grep pipe

Sorry?

I got it
Put that at the beginning of the script.

export LC_ALL=C

Valid only for the script

Thank you very much for helping