如何对字段进行排序,形成尾注导出文件格式,其中该行在地址中包含 GRAZ 作为第一行?

how can I sort a field form an Endnote Export File format where the Line contains GRAZ in the address as first line?

我有一个 Endote 导出文件,如下所示:

    %0 Journal Article
    %A Abu-Rous, M.
    %A Ingolic, E.
    %A Schuster, K. C.
    %D 2006
    %Z Cellulose
    Article
    CODEN: CELLE
    %+ Christian Doppler-Laboratory of Fibre and Textile Chemistry in Cellulosics, Institute of Texile Chemistry and Textile Physics, Leopold-Franzens-University Innsbruck, Hoechsterstrasse 73, A-6850 Dornbirn, Austria
    Research Institute for Electron Microscopy (FELMI), Technical University of Graz, A-8010 Graz, Austria
    Textile Innovation, Lenzing AG, A-4860 Lenzing, Austria
    Schuster, K.C.; Textile Innovation, , A-4860 Lenzing, Austria; email: c.schuster@lenzing.com
    %~ Scopus
    %G English
    
    
    
    %0 Journal Article
    %P 5003-5011
    %! Ursolic acid from Trailliaedoxa gracilis induces apoptosis in medullary thyroid carcinoma cells
    %@ 17912997
    %R 10.3892/mmr.2015.4053
    %1 in_author_address; 
    %F 8
    %K Apoptosis
    Bioactive agents
    %Z Mol. Med. Rep.
    Article
    Chemicals/CAS: caspase 8; ursolic acid, 77-52-1; I kappa B kinase, 209902-66-9; Antineoplastic Agents, Phytogenic; Caspase 8; I-kappa B Kinase; IKBKG protein, human; Plant Extracts; Triterpenes; ursolic acid
    Tradenames: cpt, Sigma Aldrich; rotichrom, karlsruhe, Germany
    %+ Department of Pathophysiology and Immunology, Center of Molecular Medicine, Medical University of Graz, 31a Heinrichstrasse, Graz A, 8010, Austria
    Department of Biochemistry and Molecular Biology, Shanghai Medical School, Fudan University, Shanghai, 200433, China
    Department of Pharmacognosy, Institute of Pharmacy, Center of Molecular Biosciences, Leopold Franzens University of Innsbruck, Innsbruck A, 6010, Austria
    Core Unit of Biomedical Research, Division of Laboratory Animal Science and Genetics, Medical University of Vienna, Himberg A, 2325, Austria
    Research Institute for Electron Microscopy and Fine Structure Research, University of Technology Graz, Graz A, 8010, Austria
    Pfragner, R.; Department of Pathophysiology and Immunology, 31a Heinrichstrasse, Austria; email: roswitha.pfragner@medunigraz.at
    %~ Scopus C2 - 26151624
    %G English


    

%+开头的字段包含作者地址,根据作者地址(1对n关系)可以由更多行组成。 每个作者地址都用换行符(linebreak)分隔

现在我想问一下如何按GRAZ所在的行对这个字段进行排序。 格拉茨所在的这一行,它们应该是列表中的第一行。

有没有办法通过 bash 文本处理工具来做到这一点,或者需要我编写一个 Delphi 的程序来访问和导入尾注导出转储。

上面这个例子的输出应该是

    %0 Journal Article
    %A Abu-Rous, M.
    %A Ingolic, E.
    %A Schuster, K. C.
    %D 2006
    %Z Cellulose
    Article
    CODEN: CELLE
    %+ Research Institute for Electron Microscopy (FELMI), Technical University of Graz, A-8010 Graz, Austria
    Christian Doppler-Laboratory of Fibre and Textile Chemistry in Cellulosics, Institute of Texile Chemistry and Textile Physics, Leopold-Franzens-University Innsbruck, Hoechsterstrasse 73, A-6850 Dornbirn, Austria
    Textile Innovation, Lenzing AG, A-4860 Lenzing, Austria
    Schuster, K.C.; Textile Innovation, , A-4860 Lenzing, Austria; email: c.schuster@lenzing.com
    %~ Scopus
    %G English
    
    
    
    %0 Journal Article
    %P 5003-5011
    %! Ursolic acid from Trailliaedoxa gracilis induces apoptosis in medullary thyroid carcinoma cells
    %@ 17912997
    %R 10.3892/mmr.2015.4053
    %1 in_author_address; 
    %F 8
    %K Apoptosis
    Bioactive agents
    %Z Mol. Med. Rep.
    Article
    Chemicals/CAS: caspase 8; ursolic acid, 77-52-1; I kappa B kinase, 209902-66-9; Antineoplastic Agents, Phytogenic; Caspase 8; I-kappa B Kinase; IKBKG protein, human; Plant Extracts; Triterpenes; ursolic acid
    Tradenames: cpt, Sigma Aldrich; rotichrom, karlsruhe, Germany
    %+ Department of Pathophysiology and Immunology, Center of Molecular Medicine, Medical University of Graz, 31a Heinrichstrasse, Graz A, 8010, Austria
    Department of Biochemistry and Molecular Biology, Shanghai Medical School, Fudan University, Shanghai, 200433, China
    Department of Pharmacognosy, Institute of Pharmacy, Center of Molecular Biosciences, Leopold Franzens University of Innsbruck, Innsbruck A, 6010, Austria
    Core Unit of Biomedical Research, Division of Laboratory Animal Science and Genetics, Medical University of Vienna, Himberg A, 2325, Austria
    Research Institute for Electron Microscopy and Fine Structure Research, University of Technology Graz, Graz A, 8010, Austria
    Pfragner, R.; Department of Pathophysiology and Immunology, 31a Heinrichstrasse, Austria; email: roswitha.pfragner@medunigraz.at
    %~ Scopus C2 - 26151624
    %G English

如果有任何有趣的建议,我将非常高兴和感激。

请您尝试以下操作:

#!/bin/bash

shopt -s nocasematch            # make the match case-insensitive

# print the arrays and empty them
flush() {
    printf "%s" "%+ "
    printf "%s\n" "${out1[@]}" "${out2[@]}"
    out1=(); out2=()
}

while IFS= read -r line; do     # read the file line by line
    if (( auth )); then         # now in the "Author Address" context
        if [[ $line = "%"* ]]; then
                                # end of the "Author Address" context
            auth=0
            flush               # print the arrays
            echo "$line"        # print current line
        else
            [[ $line = *"GRAZ"* ]] && out1+=("$line") || out2+=("$line")
                                # if the line contains "GRAZ" store it in the array out1, else out2
        fi
    else
        if [[ $line = "%+"* ]]; then
            auth=1              # enter in the "Author Address" context
            [[ $line = *"GRAZ"* ]] && out1+=("${line:3}") || out2+=("${line:3}")
                                # ${line:3} removes leading 3 characters
        else
            echo "$line"
        fi
    fi
done < input_file

输出:

%1 Journal Article
%A Abu-Rous, M.
%A Ingolic, E.
%A Schuster, K. C.
%D 2006
%Z Cellulose
Article
CODEN: CELLE
%+ Research Institute for Electron Microscopy (FELMI), Technical University of Graz, A-8010 Graz, Austria
Christian Doppler-Laboratory of Fibre and Textile Chemistry in Cellulosics, Institute of Texile Chemistry and Textile Physics, Leopold-Franzens-University Innsbruck, Hoechsterstrasse 73, A-6850 Dornbirn, Austria
Textile Innovation, Lenzing AG, A-4860 Lenzing, Austria
Schuster, K.C.; Textile Innovation, , A-4860 Lenzing, Austria; email: c.schuster@lenzing.com
%~ Scopus
%G English



%0 Journal Article
%P 5003-5011
%! Ursolic acid from Trailliaedoxa gracilis induces apoptosis in medullary thyroid carcinoma cells
%@ 17912997
%R 10.3892/mmr.2015.4053
%1 in_author_address;
%F 8
%K Apoptosis
Bioactive agents
%Z Mol. Med. Rep.
Article
Chemicals/CAS: caspase 8; ursolic acid, 77-52-1; I kappa B kinase, 209902-66-9; Antineoplastic Agents, Phytogenic; Caspase 8; I-kappa B Kinase; IKBKG protein, human; Plant Extracts; Triterpenes; ursolic acid
Tradenames: cpt, Sigma Aldrich; rotichrom, karlsruhe, Germany
%+ Department of Pathophysiology and Immunology, Center of Molecular Medicine, Medical University of Graz, 31a Heinrichstrasse, Graz A, 8010, Austria
Research Institute for Electron Microscopy and Fine Structure Research, University of Technology Graz, Graz A, 8010, Austria
Pfragner, R.; Department of Pathophysiology and Immunology, 31a Heinrichstrasse, Austria; email: roswitha.pfragner@medunigraz.at
Department of Biochemistry and Molecular Biology, Shanghai Medical School, Fudan University, Shanghai, 200433, China
Department of Pharmacognosy, Institute of Pharmacy, Center of Molecular Biosciences, Leopold Franzens University of Innsbruck, Innsbruck A, 6010, Austria
Core Unit of Biomedical Research, Division of Laboratory Animal Science and Genetics, Medical University of Vienna, Himberg A, 2325, Austria
%~ Scopus C2 - 26151624
%G English

输出与您的预期输出略有不同,一个是因为 ... University of Technology Graz ... 行比您预期结果中不包含 GRAZ 的其他行晚,另一个是因为 medunigraz 被认为匹配 GRAZ.