Add space between files paths

4 find text-processing

I have a list of folders and inside every folder I have the file " file.txt" which has the same name in all the folders. I wanted to collect the path for this file from all the folders and save it in a text file. In order to do so, I ran the following command in the parent folder :

find $PWD -type f -name "file.txt" > paths.txt
Run Code Online (Sandbox Code Playgroud)

This command stored all the paths to this file from all the folders, in the file"path.txt " as follow:

a/b/c/1/file.txt
a/b/c/2/file.txt
a/b/c/3/file.txt
a/b/c/4/file.txt
a/b/c/5/file.txt
a/b/c/6/file.txt
a/b/c/7/file.txt
.
.
.
.
Run Code Online (Sandbox Code Playgroud)

How can I create space between the lines in the file "path.txt" so it can show as follow:

/a/b/c/1/file.txt /a/b/c/2/file.txt /a/b/c/3/file.txt /a/b/c/4/file.txt /a/b/c/5/file.txt /a/b/c/6/file.txt /a/b/c/7/file.txt ...
Run Code Online (Sandbox Code Playgroud)

Sat*_*ura 7

另一种方式,假设 GNU find(1),只是为了好玩:

find $PWD -type f -name "file.txt" -printf '%p '
Run Code Online (Sandbox Code Playgroud)


Ste*_*ris 5

You can replace the LF character with a space using the 'tr' command

tr '\012' ' ' < path.txt
Run Code Online (Sandbox Code Playgroud)

This can be part of the original command:

find $PWD -type f -name "file.txt" | tr '\012' ' ' > paths.txt
Run Code Online (Sandbox Code Playgroud)