简体   繁体   中英

Regex syntax error with Sed command in Ubuntu 9.04

I have the sed command like this:

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:

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

which aim to replace value of secret by key in clients.conf file. For Example, if key is 00000000000000000000000000000002, the content of clients.conf should be changed as following:

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

Could anyone help me for this situation?

I think you need add a ; between command n and command s , like this

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

This working in my cygwin environment.

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.

Like this:

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

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