'bash oneliner search for files and dump name and content into new file
as title says I need to write a bash oneliner that finds all txt files and, for each, writes name and content into another file. So far I wrote:
find . -name "*.txt" -type f -exec cat {} + >> find_txt
It works but now I don't know how to write the file name before its content. For example, given the following files
dirA/file1.txt
dirA/file2.txt
dirB/file3.txt
dirC/file4.txt
dirC/file5.txt
The oneliner should create find_txt
file with the following content:
dirA/file1.txt
content of file1.txt
dirA/file2.txt
content of file2.txt
dirB/file3.txt
content of file3.txt
dirC/file4.txt
content of file4.txt
dirC/file5.txt
content of file5.txt
Any clue? Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|