Solved sed: negation of a range is broken?

aragats

Daemon

Reaction score: 615
Messages: 1,508

I would expect the same output of the following two commands, but the first one looks wrong to me:
Code:
% echo abc^ABC.123 | sed 's/[^A-z0-9]/_/g'
abc^ABC_123
% echo abc^ABC.123 | sed 's/[^[:alnum:]]/_/g'
abc_ABC_123
By the way, gsed does the same. Am I missing something?..
 

ljboiler

Well-Known Member

Reaction score: 155
Messages: 432

Look at the range you specify on the first command: A-z. That range includes a few characters between the A-Z and a-z, including the ^. You would need to specify the range as A-Za-z.
 
OP
aragats

aragats

Daemon

Reaction score: 615
Messages: 1,508

Thanks, [USER=6335]ljboiler[/USER] ! I haven't looked in the ASCII table for long time (-;
 
Top