Imagine I have a folder/file structure like the following
a/b/c_d.e
a/b/d.f
I want to mangle the filename so that path separators become _
, and between the folder and file is a -
, and then that is prepended to the folder location.
a/b/a_b-c_d.e
a/b/a_b-d.f
What I have so far:
find . -type f -name *.c -exec sh -c "echo -n { {} | xargs dirname }; echo -n "/"; realpath --relative-to="$PWD" "{}" | tr '/' '_'" \;
Which will output
./src/ucd-tools/src
/src_ucd-tools_src_proplist.c
It seems the first echo -n
is adding new lines, but if I manually run echo -n "Hello"
it works as expected without new lines.