If you need groups of 80 files, you should do everything possible so that the names are sortable; why leading zeros were often used. Assuming you have only one underscore in the file names, and also there are no newlines in the names, then:
SOURCE="/path/to/dir" TARGET="/path/to/other/directory" ( cd $SOURCE || exit 1 ls | sort -t _ -k2,2n | awk -v target="$TARGET" \ '{ file[n++] = $1 if (n >= 80) { printf "cat" for (i = 0; i < 80; i++) printf(" %s", file[i] printf(" >%s/%s.%.2d\n", target, "newfile", ++number) n = 0 } END { if (n > 0) { printf "cat" for (i = 0; i < n; i++) printf(" %s", file[i] printf(" >%s/%s.%.2d\n", target, "newfile", ++number) } }' | sh -x )
Two directories are indicated (where files are located and where summaries should be displayed); The command changes the directory to the source directory (where 800 files are located). It lists the names (you can specify the glob pattern if you need to) and sorts them numerically. The output is served in awk , which generates a shell script on the fly. It collects 80 names at a time, then generates a cat command that copies these files into a single destination file, such as "newfile.01" ; configure printf() to suit your naming and numbering conventions. Shell commands are then passed to the shell for execution.
During testing, replace sh -x with nothing, or sh -vn or something similar. Add an active shell only when you are sure that it will do what you want. Remember that the shell script is in the source folder when it is running.
Superficially, the xargs command would be convenient to use; complexity coordinates the output file number. There may be a way to do this with the -n 80 option to group 80 files at a time and some fancy way to generate a call number, but I don't know about that.
Another option is to use xargs -n to execute a shell script that can print the correct output file number, indicating that it is already in the destination directory. That would be cleaner in many ways:
SOURCE="/path/to/dir" TARGET="/path/to/other/directory" ( cd $SOURCE || exit 1 ls | sort -t _ -k2,2n | xargs -n 80 cpfiles "$TARGET" )
Where cpfiles as follows:
TARGET="$1" shift if [ $# -gt 0 ] then old=$(ls -r newfile.?? | sed -n -e 's/newfile\.//p; 1q') new=$(printf "%.2d" $((old + 1))) cat " $@ " > "$TARGET/newfile. $new fi
The test for null arguments avoids the problem of xargs executing a command once with null arguments. In general, I prefer this solution with awk .