
次の名前の次のファイルがあります。
Selection_Test_from_120118_1140118.txt
Selection_Test_from_monthly_120118_1140118.txt
ファイルから文字列を削除して2つのファイルの名前を変更するにはどうすればよいですか?
string1 --> Selection_Test.txt (remove "_from_120118_1140118")
string2 --> Selection_Test.txt (remove "_from_monthly_120118_1140118")
ここでは、既存の切り取りコマンドの代わりにパラメータ拡張方法を使用したいと思います。
答え1
Perlを使用したスタンドアロンコマンドrename
:
rename -n 's/_from_[^.]*//' *.txt
問題がなければ削除してください-n
。