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
Here is a really simple way. You said you want to cat, which implies you want to view the entire file. But you also need the filename printed.
Try this
head -n99999999 *
orhead -n99999999 file1.txt file2.txt file3.txt
Hope that helps
If you want the result in the same format as your desired output you can try:
Result:
You can put
echo -e
before and after the cut so you have the spacing between the lines as well:Result:
For solving this tasks I usually use the following command:
It's a very convenient way to concatenate files if the number of files is quite large.
I like this option
Output looks like this:
I used grep for something similar:
It does not give you a 'header', but prefixes every line with the filename.