简体   繁体   English

Ubuntu 9.04中Sed命令的正则表达式语法错误

[英]Regex syntax error with Sed command in Ubuntu 9.04

I have the sed command like this: 我有这样的sed命令:

radius_clientsfile=clients.conf
iface_netsize="/64"
wireless_prefix=fd04:bd3:80e8:3::
sed -i "/client $wireless_prefix\\$iface_netsize/ {n s/\(\W*secret\W*=\W\).*/\1$key/}" $radius_clientsfile

clients.conf has the content like this: clients.conf的内容如下:

client fd04:bd3:80e8:3::/64 {
  secret      = 00000000000000000000000000000001
}

which aim to replace value of secret by key in clients.conf file. 目的是用clients.conf文件中的密钥替换秘密值。 For Example, if key is 00000000000000000000000000000002, the content of clients.conf should be changed as following: 例如,如果密钥为00000000000000000000000000000000000002,则应按以下方式更改clients.conf的内容:

client fd04:bd3:80e8:3::/64 {
      secret      = 00000000000000000000000000000002
    }

This script work on OpenWRT attitude adjustment r35400 for armv5tejl However, it can not work in Ubuntu 9.04 with error: sed: -e expression #1, char 36: extra characters after command 该脚本适用于armv5tejl的OpenWRT姿态调整r35400,但是,它在Ubuntu 9.04中无法正常工作,并显示以下错误: sed:-e表达式#1,char 36:命令后有多余字符

Could anyone help me for this situation? 在这种情况下,有人可以帮我吗?

I think you need add a ; 我认为您需要添加一个; between command n and command s , like this 在命令n和命令s ,像这样

sed -i "/client $wireless_prefix\\$iface_netsize/ {n; s/\(\W*secret\W*=\W\).*/\1$key/}" $radius_clientsfile

This working in my cygwin environment. 这在我的cygwin环境中工作。

You need to separate the commands in the command block with a semi-colon, so add a ; 您需要用分号分隔命令块中的命令,因此请添加;。 after the n command to separate it from the following command. 在n命令之后将其与以下命令分开。

Like this: 像这样:

{n;s/\(\W*secret\W*=\W\).*/\1$key/}

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

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