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 5 years have passed since last update.

bash > fileIO > 並列化 > ls + awk > 入力ファイルをINTVLとINDX指定で分割する > bashスクリプト v0.3

Last updated at Posted at 2019-10-24
動作環境
CentOS Linux release 7.7.1908 (Core)

状況

  • bashスクリプト(ImageMagickのconvertコマンドを実行する)を並列化したい
  • 自作のlsで並列化用のファイルリスト分割をする

v0.1, v0.2

v0.3

v0.2の場合、DIR/PREFIXのようなアスタリスクで終わる場合には対応していたが、DIR/.psのように後ろに文字指定したい場合には使用できなかった。

今回はBrace Expansionの結果を配慮して対応することにした。

  • 1つ目と2つ目の引数は分割の指定用
    • 1つ目: インターバル
    • 2つ目: 開始インデックス
  • 3つ目以降にファイルリストがある (Brace Expansionの結果)

code

my_ls_skipped_191024_exec
# !/usr/bin/env bash

function myls_skipped()
{
	INTVL=$1 && INDX=$2 && echo $* | awk '{$1="";$2="";print}' | \
	xargs --max-args=1 | awk '(NR % '$INTVL' == '$INDX'){print $1}'
}

if [ $# -lt 3 ];then
    echo "[cmd] [interval] [start] [list of files]"
    echo "e.g."
    echo "[cmd] 4 1 *.ps"
    exit
fi

for elem in $(myls_skipped $*);
do
	echo $elem
done

実行分が長くなったので行連結とした。

実行例

$ bash my_ls_skipped_191024_exec 3 0 DATA/*.ps                               
DATA/tmp3.ps
$ bash my_ls_skipped_191024_exec 3 1 DATA/*.ps                               
DATA/tmp1.ps
DATA/tmp4.ps
$ bash my_ls_skipped_191024_exec 3 2 DATA/*.ps                               
DATA/tmp2.ps
DATA/tmp5.ps
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?