キーワードに基づいてファイル名を変更する

キーワードに基づいてファイル名を変更する

ファイルの名前を変更するのに助けが必要です。

$ cat q.txt
Only in /aa/bb/home/sh/POC/Backup/DDL/: comp1.txt
Only in /aa/bb/home/sh/POC/Backup/DDL/: comp.txt
Only in /aa/bb/home/sh/POC/Backup/DDL/: junk.txt
Files /aa/bb/home/sh/POC/05_26_2022/DDL/test.demo/table1.txt and /aa/bb/home/sh/POC/Backup/DDL/test.demo_table1.txt differ
Only in /aa/bb/home/sh/POC/05_26_2022/DDL: test.demo_table2.txt

$ cat q.txt | awk '/^Only/ {gsub("[/:]+","/", $3); {sub(/^.*\//, "", $3);print $NF > $3".txt"} /^Files.*differ/ {sub(/^.*\//, "", $2); print $2.txt > "different.txt"}'

現在は _ としてファイル名を提供します。

ls -lrt
   27 May 27 07:02  _aa_bb_home_sh_POC_05_26_2022_DDL.txt
   28 May 27 07:02  _aa_bb_home_sh_POC_Backup_DDL_.txt
   27 May 27 07:04 different.txt
     

以下のようなo/pが必要です

ls -lrt
   27 May 27 07:02  05_26_2022_DDL.txt
   28 May 27 07:02  Backup_DDL.txt
   27 May 27 07:04 different.txt

ベストアンサー1

おすすめ記事