tags:

views:

130

answers:

2

hi all

The following sed command replaces the OLD string with the NEW string. My target is to replace the OLD to NEW only if COMMAND word appears as the first word in the line. How to fix my sed syntax in order to replace OLD with NEW only if COMMAND is the first word in line? (Note: COMMAND word location could be after some spaces from the line beginning.)

lidia

sed "/^ *#/b; /COMMAND/ s/OLD/NEW/g"  file

  COMMAND OLD
  OLD COMMAND

after sed exe:

  COMMAND NEW
  NEW COMMAND
+1  A: 

try this: 's/^(\s*COMMAND) OLD(.*)$/\1 NEW\2/'

knittl
+2  A: 
"/^[ \t]*COMMAND/ s/OLD/NEW/g"
ghostdog74