I would like to concatenate a number of text files into one large file in terminal. I know I can do this using the cat command. However, I would like the filename of each file to precede the "data dump" for that file. Anyone know how to do this?
what I currently have:
file1.txt = bluemoongoodbeer
file2.txt = awesomepossum
file3.txt = hownowbrowncow
cat file1.txt file2.txt file3.txt
desired output:
file1
bluemoongoodbeer
file2
awesomepossum
file3
hownowbrowncow
This will print the full filename (including path), then the contents of the file. It is also very flexible, as you can use -name "expr" for the find command, and run as many commands as you like on the files.
If you want to replace those ugly ==> <== with something else
explanation:
tail -n +1 *.txt
- output all files in folder with headersed -e 's/==>/\n###/g' -e 's/<==/###/g'
- replace==>
with new line + ### and<==
with just ###>> "files.txt"
- output all to a fileyou can use this simple command instead of using a for loop,
If you like colors, try this:
or:
or: (with package 'multitail' installed)
This method will print filename and then file contents:
Output:
This should do the trick as well:
Means:
You further can combine searches trough boolean operators like
-and
or-or
.find -ls
is nice, too.