简体   繁体   English

sed命令在solaris中工作,但在Linux中不工作

[英]sed command is working in solaris but not in Linux

I am new to shell scripting and sed command. 我是shell脚本和sed命令的新手。

The following sed command is working in Solaris but giving error in Linux: 以下sed命令在Solaris中有效但在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). 似乎Linux Sed不喜欢你的Az (两次)。 It doesn't really make sense, anyway. 无论如何,它真的没有意义。

Use [AZ] (upper-case Z) 使用[AZ] (大写Z)

As blue112 said, Az as a range makes no sense. 正如blue112所说, Az作为一个范围毫无意义。 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. sed的。Solaris是解释这是“为ASCII码A通过为ASCII码z ”,在这种情况下,你可能会产生意想不到的结果。 AZ occurs before az in ASCII, but there are a few characters falling between Z and a . AZ在ASCII之前出现在az之前,但在Za之间有一些字符。

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). 以下是一个显示Solaris sed的示例(本例中为Solaris 8)。 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.) (请注意, 3未被替换,因为它不属于指定的ASCII范围。)

GNU sed is protecting you from shooting yourself in the foot by mistake. GNU sed可以防止你误入射自己的脚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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