perl -e 'for(@ARGV){open(I,"<$_");s/\.[^\.]*\-[^\-]*$/.MERGED.txt/;open(O,">>$_");print O $_ while ;close(O);close(I)}' file.abc.part-1.txt file.abc.part-2.txt file.abc.part-3.txt file.def.part-1.txt file.def.part-2.txt