Read input files and merge them in given order and write them to input one param or one file

Dear Friends,
I am looking for a shell script to merge input files into one file .. here is my idea:

1st paramter would be outfile file (all input files content)
read all input files and merge them to input param 1
ex: if I pass 6 file names to the script then 1st file name as output file and merge rest of 5 files to 1st file:

cat file1 file2 file3 file4 file5 file6 > file1

i want above to be executed at end but trying to figure out how to read input params and call that cat command at end... the reason becuase input files are dynamic.. some times it could be 4 files, some times 5 and 8 are most input files... so script needs to read all input files and based on the count it needs to issue the cat command at end as per the no of input params..

any information would be greatly appriciated.

You can call up a list of parameters with "$@" quotes included.

You can get rid of the first argument with 'shift'.

So,

OUTPUT="$1"
shift
cat "$@" > "$OUTPUT"

thanks carona.. I did this... inputs and output are coming as below.. any way to start file's content in next line?

file1:

123
456
789

file2:

abc
def
ghi

outfile:

123
456
789abc
def
ghi

any help please?

Try an echo, this might add extra empty lines in the output file.

outfile=$1
shift
for file in $@
do
  cat $file >> $outfile
  echo >> $outfile
  shift
done

--ahamed

What generated your input files? It neglected to put ending linefeeds on them.