我有一个包含300个文件的目录,如下所示:
S221_L001_R2_001.fastq.gz S30_L001_R2_001.fastq.gz
S95_L001_R2_001.fastq.gz S159_L001_R2_001.fastq.gz
S222_L001_R2_001.fastq.gz S31_L001_R2_001.fastq.gz
S96_L001_R2_001.fastq.gz
我有一个看起来像这样的文本文件:
G1F0Blank3_S184_L001_R1_001.fastq.gz
G1F0Blank3_S184_L001_R2_001.fastq.gz
G1F0C1A_S101_L001_R1_001.fastq.gz
G1F0C1A_S101_L001_R2_001.fastq.gz
G1F0C1B_S154_L001_R1_001.fastq.gz
G1F0C1B_S154_L001_R2_001.fastq.gz
我想将文本文件中文件名前面的字符串添加到我目录中的匹配文件中。文件文件中有一个条目用于我的目录中的每个文件。我最希望能够在我的unix终端中执行此操作。
谢谢!
答案 0 :(得分:0)
# first, list all files:
ls *.gz | while read FILENAME
do
# then, get the new filename from the file
# replace filenames.txt with your TXT file
NEW_FILENAME=$( grep "$FILENAME" /path/to/filenames.txt )
# and finally, rename everything
[ "$NEW_FILENAME" != "" ] && mv "$FILENAME" "$NEW_FILENAME" -v
done
如有疑问,请在
之前备份所有内容答案 1 :(得分:0)
numpy.array