以前のバージョンディレクトリの sas ファイルを新しいバージョンディレクトリにコピーします。

以前のバージョンディレクトリの sas ファイルを新しいバージョンディレクトリにコピーします。

Unixスクリプトで古いバージョンディレクトリのsasファイルを新しいバージョンディレクトリに自動的にコピーするにはどうすればよいですか?

ここで、古いバージョン = 15_1 新しいバージョン = 16_0

/データ/一時/15_1/

-rwxr-x--- 2 mit.sas

/データ/一時/16_0

ベストアンサー1

# in bash
shopt -s extglob
cd /data/temp
dirs=$(echo $(ls [1-9]*([0-9])_[0-9] | sort -rn | head -n 2))
# if there are no other files and directories you can use "ls |" in the line above
newer="${dirs% *}"
prior="${dirs#* }"
test -z "$newer" && exit 1
test -z "$prior" && exit 1
cp -p "${prior}/mit.sas" "$newer"/

おすすめ記事