I have a text file of the following form:
dir1/sub-dir1/.../filename1 author date
dir1/sub-dir1/.../filename2 author date
.
.
.
dir2/sub-di2/.../filename1 author date
dir2/sub-dir2/.../filename2 author date
Additional details:
- Every filename listed exists precisely 1 time or 2 times. That is,
filename_n
exists precisely 1 time or 2 times. If it exists 1 time, it is in only 1 version of our software, v1 or v2, depending on the path. If it exists 2 times, the file is in both v1 and v2. - The path determines if the file is in v1 or if it is in v2.
- The text file has is tab delimitted.
- The number of subdirectories varies from file to file (hence the
...
in the code block.) - (The authors and dates were not taken from
ls
. They were generated separately, by interrogating the git commits that last recorded changes to these files.)
I am trying to use sed with a regex to transform the file so that it looks like this:
dir1/sub-dir1/.../filename1 author date dir2/sub-di2/.../filename1 author date
dir1/sub-dir1/.../filename2 author date dir2/sub-dir2/.../filename2 author date
.
.
.
If filename-n
does not have a match, then it should appear only once, not twice.
I'm looking for a way to use sed and regex to perform the transformation. It can either be written to the same file (with -i
), or it can be written to a separate file.
v1/config.yml
andv1/subproject/dir/config.yml
don't happen.v1/../config.yml
andv2/../config.yml
.