Concatenate files

Hi, I want to create a batch(bash) file to combine 23 files together. These files have the same extension. I want the final file is save to a given folder. Once it is done it will delete the 23 files.

Thanks for help. Need script.

#!/bin/sh

cat file1.ext file2.ext file3.ext....................... file23.ext > directory_of_choice/outfile.ext

rm file1.ext file2.ext file3.ext....................... file23.ext

exit 0

If these 23 files are alone in one directory, use

#!/bin/sh

cat *.ext > directory_of_choice/outfile.ext

rm *.ext

exit 0

Two questions:

  1. The combined file is in the same folder with the 23 files.
rm *.ext

will delete the final result as well.
2. How to mark the issue is resloved?

Yes, use a temporary extension to bypass the problem:

#!/bin/sh

cat *.ext > outfile.temp

rm *.ext

mv outfile.temp outfile.ext

exit 0

Every file has the same header (the first row), I only want one in the final result.

If your version of tail supports -n + and -q you can do: ( echo HEADER ; tail -q -n +2 * ) > path/to/output
tail -n +2 will strip off the headers as it reads every file, so you add one to the front with ECHO first and redirect the whole block into a new file.

awk 'FNR>1||NR==1' *.ext > outtfile.tenp