Problem using sed

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

Join Date: Mar 2008
Posts: 106
Reputation: guest7 is an unknown quantity at this point 
Solved Threads: 0
guest7 guest7 is offline Offline
Junior Poster

Problem using sed

 
0
  #1
Oct 17th, 2009
Hi,

I am trying to replace the old_string with the new_string using sed.
But i am unable to do it using the following script.

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/sh
  2.  
  3. old_string="p cnf 10 20"
  4. new_string="p cnf 98 99"
  5.  
  6. sed -e 's/old_string/new_string/' file1.txt > file2.txt

Contents of file1.txt
Shell Scripting Syntax (Toggle Plain Text)
  1. p cnf 10 20
  2. 1 2 3
  3. 4 5 6
  4. 8 9 10
  5. 11 12 30

Any help is appreciated.
Last edited by guest7; Oct 17th, 2009 at 9:34 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,049
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
 
0
  #2
Oct 17th, 2009
sed -e "s/$old_string/$new_string/" file1.txt > file2.txt
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 2
Reputation: chrislee.980 is an unknown quantity at this point 
Solved Threads: 0
chrislee.980 chrislee.980 is offline Offline
Newbie Poster
 
0
  #3
31 Days Ago
I have a little sed problem which I can't seem to figure out:
I would like to concatenate the next line of a file to the current line if the current line doesn't end in ;
I tried the next command but it doesn't seem to work:

sed '/[^;]$/{N;s/\n//;}'

Any ideas?
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Shell Scripting Forum


Views: 990 | Replies: 2
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