Combine Multiple Files into Single One File One after other

I am trying to combine 4 .dat files into one single Output file
Inputs are:- file123.dat, file256.dat, file378.dat & file490

Expected Output:-

FileName=file1
{text from file1}
EOF
{blank line}
FileName=file2
{text from file2}
EOF
{blank line}
FileName=file3
{text from file3}
EOF
{blank line}
FileName=file4
{text from file4}
EOF

I tried $ cat file123.dat file256.dat file378.dat file490.dat > Result.dat
But this one messed up first line from all files and not giving required expected output.
Thanks much.
-LanceSunny

Try:

for i in file123.dat file256.dat file378.dat file490.dat; do 
  echo "FileName=$i"
  cat "$i"
  echo "EOF"
  echo
done > Result.dat

Thanks bartus11.
But your solution is not inserting Blank Line after end of each file and combining last line of current file with first line from next file.

This is the output I'm getting for those sample files:
file a:

a
a
a

file b:

b
b
b

Result:

FileName=a
a
a
a
EOF

FileName=b
b
b
b
EOF

Are you getting different output? Or should the output be formatted in an other way?

1 Like

Thanks bartus11.
Your code worked Fine.