You need to use the echo command to print the file name I threw together a quick script that did what you asking
Code:
#!/bin/bash
output_file="out.txt"
for File in "$@"
do
echo $File >> $output_file
cat $File >> $output_file
echo "" >> $output_file
done
Note the use of the varible @ this is all the passed arguments wich is then looped though. The last echo adds a new line
I tried it on 4 files named exfile_1, exfile_2 etc.. Which took the form:
Code:
File1_Line1
File1_Line2
File1_Line3
File1_Line4
After calling the script like this
Code:
./cat_files_with_names.sh exfile_{1..4}.txt
A new file "out.txt " was created wich contained:
Code:
exfile_1.txt
File1_Line1
File1_Line2
File1_Line3
File1_Line4
exfile_2.txt
File2_Line1
File2_Line2
File2_Line3
File2_Line4
exfile_3.txt
File3_Line1
File3_Line2
File3_Line3
File3_Line4
exfile_4.txt
File4_Line1
File4_Line2
File4_Line3
File4_Line4
Also note that if the script is run twice there the new results are appended to the file in totality.
HTH - let me know if this is the solution you where looking for.