On this texthardware mac 33:33:333:33:33hardware mac 33:13:333:33:33hardware mac 33:23:333:23:34hardware mac 33:033:133:33:35...I want to replace all lines starting with hardware mac withhardware mac 00:00:00:00:00:00I have triedsed s/^hardware mac/hardware mac 00:00:00:00:00:00/gcand give erroralso the classic vim command%s:/^hardware mac/hardware mac 00:00:00:00:00:00/gcBut change only the string hardware mac leavingthe numbers untouched.How to replace string beginning with hardware macwith my string?
Vim: replace all line starting with string with line
vim
You almost got it right, you just forgot to match the rest of the line (on vim)::%s/^hardware mac.*/hardware mac 00:00:00:00:00:00/gcYou can drop the gc options at the end if you are sure of what you are doing, g is likely to be unnecessary since you won't match more than once per line.With sed it is the same thing:sed -i 's/^hardware mac.*/hardware mac 00:00:00:00:00:00/' filenameNote that sed's substitution command s does not accept a c (confirm) flag, like vim does.