944,004 Members | Top Members by Rank

Ad:
Oct 17th, 2009
0

Problem using sed

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
guest7 is offline Offline
109 posts
since Mar 2008
Oct 17th, 2009
0
Re: Problem using sed
sed -e "s/$old_string/$new_string/" file1.txt > file2.txt
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Nov 24th, 2009
0
Re: Problem using sed
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chrislee.980 is offline Offline
2 posts
since Nov 2009

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: access time of a file in unix
Next Thread in Shell Scripting Forum Timeline: strange problem in parameter passing





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


Follow us on Twitter


© 2011 DaniWeb® LLC