0

I have a problem with 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:

 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

Is anyone know how to solve this issue? Thanks!

Grego
  • 59
  • 2
  • 9

1 Answers1

2

I can see two things wrong:

  1. There are forward slashes in the string that you're attempting to use in the sed command. 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.

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.

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
Community
  • 1
  • 1
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141