简体   繁体   中英

How to append sequence ID in the file name?

I have hundreds of FASTA files and want to add complete header of first sequence in the file names using bash.

Example: 1.fas

>abc_files657_XXX

ATCG...

2.fas

>def_ID

ACTG....

What I want:

1_abc_files657_XXX.fas

2_def_ID.fas

I know I can use:

for file in *.fas; do ..

... but that's all I know. Thank you!

You want to rename all .fas files to the first line in the files?

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

Eg:

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

Will become:

john_doe.fas
jane_baz.fas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM