G/^f/
s/foo/test/
&
w
