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.

#!/bin/sh

old_string="p cnf 10 20"
new_string="p cnf 98 99"

sed -e 's/old_string/new_string/' file1.txt > file2.txt

Contents of file1.txt

p cnf 10 20
1 2 3
4 5 6
8 9 10
11 12 30

Any help is appreciated.

Recommended Answers

All 2 Replies

sed -e "s/$old_string/$new_string/" file1.txt > file2.txt

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.