Hello,

I have about 30 VCF files with file names as ID_001.new.vcf. I want to extract only the "ID_001" part from the file name and change it in the header line of the VCF file where "Sample1" is given. 

    #CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  Sample1

So that the result looks like that: 

     #CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  ID_001

How can I do it ? I tried to use echo in bash and extract the IDs from the Filename but I am unable to iterate it to change inside the file.
Thanks for your help.
In bash this should do.

    for i in *.new.vcf
    do
            ID_NAME=$(basename "$i" .new.vcf)
            sed -i "1s|Sample1|$ID_NAME|g" $i
    done

Caution: I have used -i with sed. So the actual files will get edited in place. 

Now  added 1s also as to limit the replacement to first line alone.