944,198 Members | Top Members by Rank

Ad:
Nov 9th, 2009
0

Error using sed.

Expand Post »
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?

Shell Scripting Syntax (Toggle Plain Text)
  1. sed '/'$npname'.*in/d' parts.txt > parts.tmp
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Mattpd is offline Offline
47 posts
since Nov 2009
Nov 10th, 2009
0
Re: Error using sed.
Why not use grep ?
Shell Scripting Syntax (Toggle Plain Text)
  1. sk@svn:/tmp/daniweb$ npname="part"
  2. sk@svn:/tmp/daniweb$ egrep -vi ".*${npname}.*in.*" parts.txt
  3. sk@svn:/tmp/daniweb$ npname="part part"
  4. sk@svn:/tmp/daniweb$ egrep -vi ".*${npname}.*in.*" parts.txt
  5. part1.in
  6. part3.in
  7. sk@svn:/tmp/daniweb$ cat parts.txt
  8. part1.in
  9. part part.in
  10. part3.in
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Nov 11th, 2009
1
Re: Error using sed.
Click to Expand / Collapse  Quote originally posted by Mattpd ...
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?

Shell Scripting Syntax (Toggle Plain Text)
  1. sed '/'$npname'.*in/d' parts.txt > parts.tmp
It makes a difference the quotation scheme.
sed "/$npname.*in/d" parts.txt > parts.tmp
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Nov 11th, 2009
0
Re: Error using sed.
Click to Expand / Collapse  Quote originally posted by Aia ...
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.

Shell Scripting Syntax (Toggle Plain Text)
  1. sed '/'"$npname".*in'/d' parts.txt > parts.tmp
Reputation Points: 10
Solved Threads: 0
Light Poster
Mattpd is offline Offline
47 posts
since Nov 2009
Nov 12th, 2009
0
Re: Error using sed.
That looks strikingly similar to the code Aia provided

Please mark this thread as solved if you have found an answer to your question and good luck!
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Nov 19th, 2009
0
Re: Error using sed.
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!
Reputation Points: 10
Solved Threads: 0
Light Poster
Mattpd is offline Offline
47 posts
since Nov 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Software version upgrade using shell scripting
Next Thread in Shell Scripting Forum Timeline: Using user input in BASH array.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC