In this case, dividing and foldering in advance will make it easier to handle.
This section describes how to split files and classify folders according to the number of lines using only Shell.
Result
The following is the directory structure before execution.
.
├── sample.csv
├── main.sh
The following is the description of main.sh
sample.csv has 100 rows of data
※Error handling is omitted.
#!/bin/shset-e# file path[!-e"$1"]&&exit 1 ||datafile="$1"# File extension deletionfilename="${datafile%.*}"# Get number of linesrow=$(grep-c''$datafile)# Obtaining the number of splitssep="$2"# Number of directories createddir_cnt=$(awk-vrow="$row"-vsep="$sep"'BEGIN {
i=row/sep
printf("%d\n",i+=i<0?0:0.999)
}
')# Folder creationseq-f"${filename}_%01.0f" 1 ${dir_cnt} |
xargs mkdir-p# File divisionsplit-l${sep}-a 2 $datafile"${filename}_"# File movementcount=1
for i in`find .-type f -name"${filename}_*" | sort`do
mv$i"${filename}_${count}/${i//_*/_${count}}.csv"let count++
done
Run as follows.
sh main.sh sample.csv 25
After executing, check that the directory structure is as follows.
Top comments (0)