简体   繁体   English

sed故障排除的无终止`s'命令

[英]Unterminated `s' command with sed troubleshooting

I have a problem with sed. 我对sed有问题。 I want to replace the entire specific line number for multiple lines in multiples documents. 我想用多个文档中的多行替换整个特定行号。

This the bash command for 1 specific line in 1 specific document: 此bash命令用于1个特定文档中的1个特定行:

 BNAME=$(basename $FILE .pdb)
 psfgen1="pdb ./sedpdb/${BNAME}.pdb/"
 sed -i '8s/'.*'/'${psfgen1}'/' ./psfgen.inp

And I get this error : sed: -e expression #1, char 60: unterminated `s' command 我得到这个错误:sed:-e expression#1,char 60:unterminated`s'command

Is anyone know how to solve this issue? 有谁知道如何解决这个问题? Thanks! 谢谢!

I can see two things wrong: 我看错了两件事:

  1. There are forward slashes in the string that you're attempting to use in the sed command. 您要在sed命令中使用的字符串中有正斜杠。 These will be interpreted as part of the command, so you should use a different delimiter. 这些将被解释为命令的一部分,因此您应该使用其他定界符。
  2. The * is unquoted, so will be glob-expanded by the shell to the names of all the files in the directory. *是无引号的,因此将被shell全局扩展为目录中所有文件的名称。

Reliably using shell variables in string substitutions is non-trivial but can be done using one of the approaches shown in the answers to this question . 在字符串替换中可靠地使用shell变量并非易事,但可以使用此问题答案中显示的方法之一来完成。

In your case, it looks like you can probably get away with using another character as the delimiter, such as @ : 在您的情况下,看起来您可能可以避免使用另一个字符作为分隔符,例如@

sed -i "8s@.*@${psfgen1}@" ./psfgen.inp

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

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