0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CentOSのshellで学習データを分割する。

Last updated at Posted at 2021-06-29

概要

CentOSのshell scriptでデータファイルを分割する。

環境

CentOS Linux release 8.2.2004 (Core)
GNU bash, バージョン 4.4.19(1)-release (x86_64-redhat-linux-gnu)

Macでは動かないので注意

やること

  1. 現在いる場所にsplit_from, split_to1, split_to2のディレクトリを作成
  2. split_fromの中に0.txt~9.txtの何も書かないファイルを作成
  3. split_fromからランダムにsplit_to1に3つ、split_to2には7つファイルを移動

shellのプログラム

以下のようになる。

root_dir="`pwd`"
mkdir split_from
mkdir split_to1
mkdir split_to2

cd $root_dir
cd ./split_from
for ((i=0 ; i<10 ; i++))
do
touch $i".txt"
done
cd $root_dir
FROM_DIR="./split_from/"
TO_DIR1='./split_to1/'
TO_DIR2='./split_to2/'

DIR1_num=$((3))
DIR2_num=$((7))

find $FROM_DIR -type f | sort -R | tail -n $DIR1_num | xargs mv -t $TO_DIR1
find $FROM_DIR -type f | sort -R | tail -n $DIR2_num | xargs mv -t $TO_DIR2
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?