如何在文件名中附加序列 ID?

How to append sequence ID in the file name?

我有数百个 FASTA 文件,想使用 bash 在文件名中添加完整的 header 第一个序列。

示例: 1.fas

>abc_files657_XXX

ATCG...

2.fas

>def_ID

ACTG....

我想要的:

1_abc_files657_XXX.fas

2_def_ID.fas

我知道我可以使用:

for file in *.fas; do ..

...但我只知道这些。谢谢!

您想将所有 .fas 文件重命名为文件中的第一行吗?

for file in *.fas; do
    [ -e "$file" ] || continue
    mv -- "$file" "$(head -1 -- "$file").fas"
done

例如:

% cat 1.fas
john_doe
..
more text
% cat 2.fas
jane_baz

将成为:

john_doe.fas
jane_baz.fas