0

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
3
Contributors
5
Replies
7
Views
8 Years
Discussion Span
Last Post by Mattpd
0

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
1

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
0

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
0

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!

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.