スピード

スピード

sourcefile.txt10000行(毎日増加)を含むファイルを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

おすすめ記事