user1428900
user1428900

Reputation: 151

Shell Script: Replace text

machineName=machine1

Replace: MACHINEDOTS="'uname -n'" to MACHINEDOTS="machine1"

I tried the following sed cmd,

sed 's/MACHINEDOTS="'uname -n'"/MACHINEDOTS="'$machineName'"/g' tmp mv -f tmp path

Error displayed: sed: invalid option -- '"'

Upvotes: 0

Views: 549

Answers (2)

Don Stewart
Don Stewart

Reputation: 137937

sed 's/MACHINEDOTS="'uname -n'"/MACHINEDOTS="'$machineName'"/g' tmp mv -f tmp path

Do you mean to evaluate uname -n? It will need to be in back ticks. Like so:

$ sed 's/\(MACHINEDOTS="\)'`uname -n`'"/\1'$machineName'"/g'

Upvotes: 0

Frank Schmitt
Frank Schmitt

Reputation: 30765

When I try to run your example on Mac OS X 10.7, I get an "unterminated substitute pattern" because you used a double quote " instead of either a single quote ' or a backquote `.

Replacing the double quote with a single quote and getting rid of the garbage after tmp (did you mean && mv -f tmp path ?) like this:

sed 's/MACHINEDOTS=''uname -n''/MACHINEDOTS="'$machineName'"/g' tmp 

works, but I'm not 100% sure whether this is what you want.

Upvotes: 1

Related Questions