sourcefile.txt
10000行(毎日増加)を含むファイルを30個の同じファイルに分割したいと思います。呼び出されたディレクトリがあり、prog1
分割されprog30
たファイルを同じファイル名でこのディレクトリに保存したいと思います。例えば。/prog1/myfile.txt
/prog2/myfile.txt
/prog30/myfile.txt
divide.sh
これはディレクトリで実行と呼ばれるbashスクリプトです。prog
#!/bin/bash
programpath=/home/mywebsite/project/a1/
array=/prog1/
totalline=$(wc -l < ./sourcefile.txt)
divide="$(( $totalline / 30 ))"
split --lines=$divide $./prog1/myfile.txt
exit 1
fi
ベストアンサー1
#!/bin/bash
# assuming the file is in the same folder as the script
INPUT=large_file.txt
# assuming the folder called "output" is in the same folder
# as the script and there are folders that have the patter
# prog01 prog02 ... prog30
# create that with mkdir output/prog{01..30}
OUTPUT_FOLDER=output
OUTPUT_FILE_FORMAT=myfile
# split
# -n -> 30 files
# $OUTPUT_FILE_FORMAT -> should start with this pattern
# --numeric-suffixes=1 -> end of file name should start from 01
split -n 30 $INPUT $OUTPUT_FILE_FORMAT --numeric-suffixes=1
# move all files to their repective directories
for i in {01..30}
do
mv $OUTPUT_FILE_FORMAT$i $OUTPUT_FOLDER/prog$i/myfile.txt
done
echo "done :)"
exit
これには分割コマンドで十分です。ただし、ここの解決策では、フォルダ名をprog01
次から始める必要があります。prog1