Visit each line that has the key pattern using the global command and do a (global) substitution on that same pattern at each visited line:
:g/\.\\\(\S\+\) ()/ s//.\\\1 (\1)/g
The pattern, which is used in both the global and substitution operations:
\.\\ : period and backslash
\(\S\+\) : non-empty, non-space string inside a capturing group (\(...\)) ...
Is there a better way?
In Vim there are always too many ways. I'd do it like this:
" get result as List
let output = systemlist('myprog')
echoerr 'Command failed! Error message:' output
" add output on top
call append(0, output)
" delete the rest
call deletebufline("%", len(output) + 1, "$")
" go to first ...