I am trying to delete any line of text that contains "$npname" and the word "in." The script works if $npname is only one word, but if it is more than one work I get "error: unterminated address regex" How can I fix this?

sed '/'$npname'.*in/d' parts.txt > parts.tmp

Why not use grep ?

sk@svn:/tmp/daniweb$ npname="part"
sk@svn:/tmp/daniweb$ egrep -vi ".*${npname}.*in.*" parts.txt
sk@svn:/tmp/daniweb$ npname="part part"
sk@svn:/tmp/daniweb$ egrep -vi ".*${npname}.*in.*" parts.txt
part1.in
part3.in
sk@svn:/tmp/daniweb$ cat parts.txt
part1.in
part part.in
part3.in

I am trying to delete any line of text that contains "$npname" and the word "in." The script works if $npname is only one word, but if it is more than one work I get "error: unterminated address regex" How can I fix this?

sed '/'$npname'.*in/d' parts.txt > parts.tmp

It makes a difference the quotation scheme.

sed "/$npname.*in/d" parts.txt > parts.tmp

It makes a difference the quotation scheme.

sed "/$npname.*in/d" parts.txt > parts.tmp

After trying everything I could think of I finally came up with this which finally worked.

sed '/'"$npname".*in'/d' parts.txt > parts.tmp

That looks strikingly similar to the code Aia provided :P

Please mark this thread as solved if you have found an answer to your question and good luck!

Similar but not exactly the same. I had to move the double quotes inside, and add two sets of single quotes. Thanks for the help!

This question has already been answered. Start a new discussion instead.