Q:

how to compare a part of header file(fasta) and fit this to one file together? 

I have more fasta files in a directory that have the same beginning but different ends:
file1abgff
-----------

file2adferr
------------

file3adfr
----------

file1adcef
-----------

How to compare the beginning of all files with each another in a directory and fit the matches together to one new file (example >file1abgffadcef)? 

A:

This code seems to solve your problem. 
Suppose you have the input file:
cat input
>file1abgff
>file2adferr
>file3adfr
>file1adcef

Here is my solution:
 sed 's/[0-9]/& /' input | awk  '{a[$1]=($1 in a ?  a[$1]"|"$2 : $0)}END{for (i in a){print a[i]}}' | sed 's/ //' | grep  "|" | sed 's/|//'

>file1abgffadcef

