Sumanth
Sumanth

Reputation: 605

sed command is working in solaris but not in Linux

I am new to shell scripting and sed command.

The following sed command is working in Solaris but giving error in Linux:

sed -n 's/^[a-zA-z0-9][a-zA-z0-9]*[ ][ ]*\([0-9][0-9]*\).*[/]dir1[/]subdir1\).*/\2:\1/p'

The error is:

sed: -e expression #1, char 79: Invalid range end

I have no clue why it is giving invalid range end error.

Upvotes: 3

Views: 136

Answers (2)

Dan Lowe
Dan Lowe

Reputation: 56568

As blue112 said, A-z as a range makes no sense. Solaris sed is interpreting this as "the ASCII code for A through the ASCII code for z", in which case you could have unintended matches. A-Z occurs before a-z in ASCII, but there are a few characters falling between Z and a.

59 Y
5a Z
----
5b [
5c \
5d ]
5e ^
5f _
60 `
----
61 a
62 b

Here is an example showing Solaris sed (Solaris 8 in this case). Given this range, it substitutes _ and \ as well as the alphabetics you were apparently targeting.

% echo "f3oo_Ba\\r" | /usr/bin/sed  's/[A-z]/./g';echo
.3.....

(Note that the 3 was not substituted as it does not fall into the specified ASCII range.)

GNU sed is protecting you from shooting yourself in the foot by mistake.

Upvotes: 3

blue112
blue112

Reputation: 56462

It seems like Linux Sed doesn't like your A-z (twice). It doesn't really make sense, anyway.

Use [A-Z] (upper-case Z)

Upvotes: 5

Related Questions