简体   繁体   中英

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.

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

Use [AZ] (upper-case Z)

As blue112 said, Az 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. AZ occurs before az 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM