复制特定单词后和特定单词后的过去

时间:2015-09-30 11:37:12

标签: linux sed copy-paste

我想以简单的方式复制和粘贴任务。我有一个超过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";

1 个答案:

答案 0 :(得分:1)

也许您可以使用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

  4. 因此,最后一个命令将通过在它们之间插入分隔符来粘贴这些行。