find
+ bash
:
Exemplo de estrutura de pastas (por exemplo, 1080_a
e 2085_a
):
$ tree 1008_a/ 2085_a/
1008_a/
├── C85CBANXX_s6_1_O07_0452_SL137634.fastq.gz
└── C85CBANXX_s6_2_O07_0452_SL137634.fastq.gz
2085_a/
├── C7V65ANXX_s6_1_M19_0413_SL131164.fastq.gz
└── C7V65ANXX_s6_2_M19_0413_SL131164.fastq.gz
O trabalho:
find . -type f -regextype posix-egrep \
-regex ".*/[0-9]{4}_a/[[:alnum:]_]+_[12]_[[:alnum:]_]+\.fastq\.gz$" -exec bash -c \
'path=${0%/*}/; bn=${0##*/}; dir_n=${0%/*}; dir_n=${dir_n##*/};
new_fn=$(sed -E "s/.+_([12])_.+(\.fastq\.gz)$/${dir_n}_R/" <<<"$bn");
mv "$0" "$path$new_fn"' {} \;
Resultados:
$ tree 1008_a/ 2085_a/
1008_a/
├── 1008_a_R1.fastq.gz
└── 1008_a_R2.fastq.gz
2085_a/
├── 2085_a_R1.fastq.gz
└── 2085_a_R2.fastq.gz