Artificial intelligent assistant

multiple group capture/modify with sed I'd like to use `sed` to modify the output of `gcc -MM` which generates a dependency graph for C/C++ files. The input looks like: ThreadCrash.o : ThreadCrash.cpp ThreadCrash.h hdr1.h \ ../inc/hdr2.h ../inc/hdr3.h \ ../inc/hdr4.h ../inc/hdr4.h And I need to make it look like: ThreadCrash.o : \ ThreadCrash.cpp \ ThreadCrash.h \ hdr1.h \ ../inc/hdr2.h \ ../inc/hdr3.h \ ../inc/hdr4.h \ ../inc/hdr4.h For the 'find' part of the substitute I've been trying to "repeat" capture groups like `(.*)*` but can't figure out how to form the replace string. I'm not tied to sed so any simple approach, eg `awk` etc, would be greatly welcome. Thanks!

Remove the space at the start of the line, then replace any space followed by something other than a colon or backslash with space-backslash-newline-char sequence:

Using GNU sed:


sed -E 's/^ //; s/ ([^:\\])/ \\\
\1/g'

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 659555089ab6dafe3e651d3d57570db8