I'd like to replace the space (
) character(s) in the name of the branches with an underscore (
_). For example, say I have a sedtest file containing:
Node-path: trunk/ Node-path: trunk/src/lib 0 Node-path: trunk/src/lib 0/bla.txt Node-path: branches/ branch0-blabla_blabla/src Node-path: branches/ branch0-blabla_blabla Node-path: branches/branch1 stuffthing Node-path: branches/branch1 stuffthing/src/lib 0 Node-path: branches/branch1 stuffthing/src/lib 0/bla.txt Node-path: branches/branch2stuffthing/src/lib 0/bl a.txt
I'd like it to be modified like this:
Node-path: trunk/ Node-path: trunk/src/lib 0 Node-path: trunk/src/lib 0/bla.txt Node-path: branches/_branch0-blabla_blabla/src Node-path: branches/_branch0-blabla_blabla Node-path: branches/branch1_stuffthing Node-path: branches/branch1_stuffthing/src/lib 0 Node-path: branches/branch1_stuffthing/src/lib 0/bla.txt Node-path: branches/branch2stuffthing/src/lib 0/bl a.txt
I'm having an issue similar as the one described in this SO question. However, that question requests to replace all the spaces in the path. I'd like to replace the spaces only in the branches names.
From that other question, I have modified the
sed command to:
sed '/^Node-path: branches\//s/ /_/2' < sedtest
But it also modifies the last line to
Node-path: branches/branch2stuffthing/src/lib_0/bl a.txt, which should be left untouched. My experience with
sed being quite limited, I've been unable to properly limit the 'search region' to what is between
branches/ and the following
$, whichever comes first. I'm using CentOS 7.
As for what I'm trying to accomplish: I'm trying to port our SVN repository to a git one, and according to this answer on SO and on my personal experience, git branches names can't have spaces in them. I'm trying to fix this through a svn dump as suggested on svnbook.red-bean.com.
I suppose I could grep all the faulty branches and manually replace the strings, but that would be less generic, more work, and much less entertaining.