Error using sed.

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2009
Posts: 42
Reputation: Mattpd is an unknown quantity at this point 
Solved Threads: 0
Mattpd Mattpd is online now Online
Light Poster

Error using sed.

 
0
  #1
27 Days Ago
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,254
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 579
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #2
26 Days Ago
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
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic
 
1
  #3
25 Days Ago
Originally Posted by Mattpd View 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
It makes a difference the quotation scheme.
sed "/$npname.*in/d" parts.txt > parts.tmp
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 42
Reputation: Mattpd is an unknown quantity at this point 
Solved Threads: 0
Mattpd Mattpd is online now Online
Light Poster
 
0
  #4
25 Days Ago
Originally Posted by Aia View Post
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,254
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 579
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #5
24 Days Ago
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!
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 42
Reputation: Mattpd is an unknown quantity at this point 
Solved Threads: 0
Mattpd Mattpd is online now Online
Light Poster
 
0
  #6
16 Days Ago
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!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC