在特定单词后复制并在特定单词后过去

copy after specific words and past after specific words

我想以简单的方式完成复制和粘贴任务。我有一个超过 3000 行的文件。在 linux 中我该怎么做?

文本文件

#: Bib Field 111
where liblibrarian = "MAIN ENTRY--MEETING NAME";
update  marc_subfield_structure set liblibrarian = "TEMEL GİRİŞ--TOPLANTI ADI", libopac = 

#: Bib Sub 111 f
where liblibrarian = "Date of a work";
update  marc_subfield_structure set liblibrarian = "Eserin tarihi", libopac = 

#: Bib Sub 111 k
where liblibrarian = "Form subheading";
update  marc_subfield_structure set liblibrarian = "Alt başlık biçimlendir", libopac = 

#: Bib Sub 111 l
where liblibrarian = "Language of a work";
update  marc_subfield_structure set liblibrarian = "Eserin dili", libopac = 

#: Bib Sub 111 n
where liblibrarian = "Number of part/section/meeting";
update  marc_subfield_structure set liblibrarian = "Parça/bölüm/toplantı sayısı", libopac = 

我要

update  marc_subfield_structure set liblibrarian = "Toplantı yeri", libopac = "Toplantı yeri" where liblibrarian = "Location of meeting";
update  marc_subfield_structure set liblibrarian = "Relator kodu", libopac = "Relator kodu" where liblibrarian = "Relator code";
update  marc_subfield_structure set liblibrarian = "Eserin adı", libopac = "Eserin adı" where liblibrarian = "Title of a work";
update  marc_subfield_structure set liblibrarian = "Relator terim", libopac = "Relator terim" where liblibrarian = "Relator term";

也许您可以使用 awk 或 sed 等其他工具轻松完成此操作。但我认为也可以通过以下方式完成:

  1. 通过以下命令创建一个只包含 'where liblibrarian ..' 部分的文件:

    grep 'where liblibrarian' <file> > first_file

  2. 创建一个只包含 'update marc_subfield_structure..' 部分的文件:

    grep 'update marc_subfield_structure' <file> > second_file

  3. 现在你有两个文件,每行包含你想要构建的最终结果的一部分。因此,您只需使用以下命令按列粘贴它们(您可以根据需要调整分隔符)。

    paste second_file first_file | column -s $'\t' -t

最后一条命令将通过在行之间插入分隔符来粘贴行。