Sed command works on Solaris, but not Linux

I am new to shell commands and sed

.

The following command sed

works on Solaris, but gives an error on Linux:

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

      

Error :

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

      

I don't know why it is giving an invalid end of range error.

+3


source to share


2 answers


It seems like Linux Sed doesn't like yours A-z

(twice). It doesn't make sense anyway.



Use [A-Z]

(uppercase Z)

+5


source


As blue112 said, A-z

as a range doesn't make sense. Solaris sed interprets this as "ASCII for A

through ASCII for z

", in which case you may have unintended matches. A-z

occurs before A-z

in ASCII, but there are multiple characters 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 (in this case Solaris 8). Given this range, it replaces _

and \

, as well as the alphabets you seem to be targeting.



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

      

(Note that 3

it was not replaced as it does not fall within the specified ASCII range.)

GNU sed protects you from wrong foot shooting.

+3


source







All Articles