パターン別にソートされたファイル

パターン別にソートされたファイル

私は、_で区切られた複数列形式の固定名構造を使用して大量のパディング管理を扱っています。

3000_12_lig_cne_158.dlg
1300_10_lig_cne_983.dlg
4000_09_lig_cne_158.dlg
5000_09_lig_cne_158.dlg
7000_09_lig_cne_158.dlg
10V1_06_lig_cne_983.dlg
10V2_11_lig_cne_158.dlg
N000_12_lig_cne_158.dlg
M000_10_lig_cne_158.dlg
E000_10_lig_cne_158.dlg

したがって、最初の列には4つの数字(例:7000)または数字と文字の組み合わせ(例:N000または10V1)を含めることができます。

いくつかのbashルーチンを使用して、最初の列名に基づいてこれらのすべての塗りつぶしを並べ替え、最初の列名と一致する各トラックのサブディレクトリを作成する必要があります。したがって、デモの入力リストには合計10個のディレクトリ(3000、1300、E000、M000、10V1、10V2など)を作成する必要があります。

最初の列に数字のみがある塗りつぶしの場合は、FORループで正規表現を使用して塗りつぶしを並べ替える次のパスを使用できます。

for i in ${FILES}/[0-9]*_*.dlg        # match the filles containing only digits in the first column
do 
    j=${i##*/}               # strip the path off from beginning to last /
    mkdir -p $OUTPUT/${j%%_*}        # create dir with the name matching the first column of the file
    mv $i $OUTPUT/${j%%_*} # move the file to the corresponded directory
done

最初の列のすべてのデモパターンと一致するように変更するにはどうすればよいですか?

ベストアンサー1

使用してください(パラメータ拡張を引用しなかったため、zshスクリプトはすでにzsh構文に含まれています)。bash

autoload zmv # best in ~/.zshrc

zmodload zsh/files # makes mkdir and mv (and a few other file manipulation
                   # utilities) builtin to speed things up.

mkmv() { mkdir -p -- $2:h && mv -- "$@"; }

(
  cd -P -- "$FILES" &&
    zmv -P mkmv '([A-Z0-9](#c4))_*.dlg' '$1/$f'
)

[A-Z0-9](#c4)4つの英語の大文字と一致します。(、でのみ一致しzsh、、、 ŔÆ

おすすめ記事