Error using sed.

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

Join Date: Nov 2009
Posts: 43
Reputation: Mattpd is an unknown quantity at this point 
Solved Threads: 0
Mattpd Mattpd is offline Offline
Light Poster

Error using sed.

 
0
  #1
Nov 9th, 2009
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,410
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: 614
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #2
Nov 10th, 2009
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,048
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: 179
Aia's Avatar
Aia Aia is offline Offline
Postaholic
 
1
  #3
Nov 11th, 2009
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: 43
Reputation: Mattpd is an unknown quantity at this point 
Solved Threads: 0
Mattpd Mattpd is offline Offline
Light Poster
 
0
  #4
Nov 11th, 2009
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,410
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: 614
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #5
Nov 12th, 2009
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: 43
Reputation: Mattpd is an unknown quantity at this point 
Solved Threads: 0
Mattpd Mattpd is offline Offline
Light Poster
 
0
  #6
30 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



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC