Skip to main content
added 154 characters in body
Source Link

I am concatenating thousands of .txt files together but I want to keep the path written above the text of each .txt file so I can refer back to the directory to review files if needed.

Example:

file1.txt has the following content:

id: 1234
info: 1234
id: abcd
info: abcd

The path to file1.txt is pathto/dir1/sub1/file1.txt

file2.txt has the following content:

id: 5678
info: 5678

The path to file2.txt is pathto/dir2/sub2/file2.txt

The .txt file after concatenating should be formatted like:

pathto/dir1/sub1/file1.txt

id: 1234
info: 1234
id: abcd
info: abcd

pathto/dir2/sub2/file2.txt

id: 5678
info: 5678

Concatenating alone does not print the path in between each concatenated .txt file which is what I am trying to accomplish.

I will also cd ~/ into pathto/ and would need to run a command from there that will recursively scan all subdirectories looking for "file.txt" files

I am concatenating thousands of .txt files together but I want to keep the path written above the text of each .txt file so I can refer back to the directory to review files if needed.

Example:

file1.txt has the following content:

id: 1234
info: 1234
id: abcd
info: abcd

The path to file1.txt is pathto/dir1/sub1/file1.txt

file2.txt has the following content:

id: 5678
info: 5678

The path to file2.txt is pathto/dir2/sub2/file2.txt

The .txt file after concatenating should be formatted like:

pathto/dir1/sub1/file1.txt

id: 1234
info: 1234
id: abcd
info: abcd

pathto/dir2/sub2/file2.txt

id: 5678
info: 5678

Concatenating alone does not print the path in between each concatenated .txt file which is what I am trying to accomplish.

I am concatenating thousands of .txt files together but I want to keep the path written above the text of each .txt file so I can refer back to the directory to review files if needed.

Example:

file1.txt has the following content:

id: 1234
info: 1234
id: abcd
info: abcd

The path to file1.txt is pathto/dir1/sub1/file1.txt

file2.txt has the following content:

id: 5678
info: 5678

The path to file2.txt is pathto/dir2/sub2/file2.txt

The .txt file after concatenating should be formatted like:

pathto/dir1/sub1/file1.txt

id: 1234
info: 1234
id: abcd
info: abcd

pathto/dir2/sub2/file2.txt

id: 5678
info: 5678

Concatenating alone does not print the path in between each concatenated .txt file which is what I am trying to accomplish.

I will also cd ~/ into pathto/ and would need to run a command from there that will recursively scan all subdirectories looking for "file.txt" files

deleted 648 characters in body
Source Link

I am concatenating thousands of txt.txt files together but I want to keep the directory namepath written somewhere above the text within the txtof each .txt file so I can refer back to the directory to review files if needed. Hope this makes sense and is possible.

{Example Example:

If file1.txt has the following content:

id: 1234
info: 1234
 
id: abcd
info: abcd

and is stored within a subdirectory titled 'sub1', which is within a directory titled, 'dir1'The path to file1.txt is pathto/dir1/sub1/file1.txt

and file2.txt has the following content:

id: 5678
info: 5678

and is stored within a subdirectory titled 'sub2', which is within a directory titled, 'dir2'The path to file2.txt is pathto/dir2/sub2/file2.txt

the output of the concatenatingThe .txt file after concatenating should be formatted like:

-pathto/dir1
--/sub1/file1.txt

id: 1234
info: 1234
 
id: abcd
info: abcd

-dir
--pathto/dir2/sub2/file2.txt

id: 5678
info: 5678}

concatenatingConcatenating alone woulddoes not list the directory (and subdirectory, if applicable) name withinprint the path in between each concatenated .txt file. I need those names written in above each entry.

Hope I explained this better.

----UPDATE---

This command which is concatenating the files properly. Not all are only within 1 subdirectory, some file.txt are buried within 3 or 4 subdirectories, so this command works well to gather them all. Nowwhat I just needam trying to have it write the directory/subdirectory name above each of the file.txt's content.

find . -iname 'file.txt' -exec cat {} ; > ~/Desktop/catfileaccomplish.txt

I am concatenating thousands of txt files together but I want to keep the directory name written somewhere above the text within the txt file so I can refer back to the directory to review files if needed. Hope this makes sense and is possible.

{Example:

If file1.txt has the following content:

id: 1234
info: 1234
 
id: abcd
info: abcd

and is stored within a subdirectory titled 'sub1', which is within a directory titled, 'dir1'

and file2.txt has the following content:

id: 5678
info: 5678

and is stored within a subdirectory titled 'sub2', which is within a directory titled, 'dir2'

the output of the concatenating file should be like:

-dir1
--sub1

id: 1234
info: 1234
 
id: abcd
info: abcd

-dir
--sub2

id: 5678
info: 5678}

concatenating alone would not list the directory (and subdirectory, if applicable) name within the concatenated .txt file. I need those names written in above each entry.

Hope I explained this better.

----UPDATE---

This command is concatenating the files properly. Not all are only within 1 subdirectory, some file.txt are buried within 3 or 4 subdirectories, so this command works well to gather them all. Now I just need to have it write the directory/subdirectory name above each of the file.txt's content.

find . -iname 'file.txt' -exec cat {} ; > ~/Desktop/catfile.txt

I am concatenating thousands of .txt files together but I want to keep the path written above the text of each .txt file so I can refer back to the directory to review files if needed.

Example:

file1.txt has the following content:

id: 1234
info: 1234
id: abcd
info: abcd

The path to file1.txt is pathto/dir1/sub1/file1.txt

file2.txt has the following content:

id: 5678
info: 5678

The path to file2.txt is pathto/dir2/sub2/file2.txt

The .txt file after concatenating should be formatted like:

pathto/dir1/sub1/file1.txt

id: 1234
info: 1234
id: abcd
info: abcd

pathto/dir2/sub2/file2.txt

id: 5678
info: 5678

Concatenating alone does not print the path in between each concatenated .txt file which is what I am trying to accomplish.

added 381 characters in body
Source Link

I am concatenating thousands of txt files together but I want to keep the directory name written somewhere above the text within the txt file so I can refer back to the directory to review files if needed. Hope this makes sense and is possible.

{Example:

If file1.txt has the following content:

id: 1234
info: 1234

id: abcd
info: abcd

and is stored within a subdirectory titled 'sub1', which is within a directory titled, 'dir1'

and file2.txt has the following content:

id: 5678
info: 5678

and is stored within a subdirectory titled 'sub2', which is within a directory titled, 'dir2'

the output of the concatenating file should be like:

-dir1
--sub1

id: 1234
info: 1234

id: abcd
info: abcd

-dir
--sub2

id: 5678
info: 5678}

concatenating alone would not list the directory (and subdirectory, if applicable) name within the concatenated .txt file. I need those names written in above each entry.

Hope I explained this better.

----UPDATE---

This command is concatenating the files properly. Not all are only within 1 subdirectory, some file.txt are buried within 3 or 4 subdirectories, so this command works well to gather them all. Now I just need to have it write the directory/subdirectory name above each of the file.txt's content.

find . -iname 'file.txt' -exec cat {} ; > ~/Desktop/catfile.txt

I am concatenating thousands of txt files together but I want to keep the directory name written somewhere above the text within the txt file so I can refer back to the directory to review files if needed. Hope this makes sense and is possible.

{Example:

If file1.txt has the following content:

id: 1234
info: 1234

id: abcd
info: abcd

and is stored within a subdirectory titled 'sub1', which is within a directory titled, 'dir1'

and file2.txt has the following content:

id: 5678
info: 5678

and is stored within a subdirectory titled 'sub2', which is within a directory titled, 'dir2'

the output of the concatenating file should be like:

-dir1
--sub1

id: 1234
info: 1234

id: abcd
info: abcd

-dir
--sub2

id: 5678
info: 5678}

concatenating alone would not list the directory (and subdirectory, if applicable) name within the concatenated .txt file. I need those names written in above each entry.

Hope I explained this better.

I am concatenating thousands of txt files together but I want to keep the directory name written somewhere above the text within the txt file so I can refer back to the directory to review files if needed. Hope this makes sense and is possible.

{Example:

If file1.txt has the following content:

id: 1234
info: 1234

id: abcd
info: abcd

and is stored within a subdirectory titled 'sub1', which is within a directory titled, 'dir1'

and file2.txt has the following content:

id: 5678
info: 5678

and is stored within a subdirectory titled 'sub2', which is within a directory titled, 'dir2'

the output of the concatenating file should be like:

-dir1
--sub1

id: 1234
info: 1234

id: abcd
info: abcd

-dir
--sub2

id: 5678
info: 5678}

concatenating alone would not list the directory (and subdirectory, if applicable) name within the concatenated .txt file. I need those names written in above each entry.

Hope I explained this better.

----UPDATE---

This command is concatenating the files properly. Not all are only within 1 subdirectory, some file.txt are buried within 3 or 4 subdirectories, so this command works well to gather them all. Now I just need to have it write the directory/subdirectory name above each of the file.txt's content.

find . -iname 'file.txt' -exec cat {} ; > ~/Desktop/catfile.txt

added 92 characters in body
Source Link
Gilles Quénot
  • 36.7k
  • 7
  • 74
  • 97
Loading
added 2 characters in body
Source Link
Loading
added 729 characters in body
Source Link
Loading
Source Link
Loading