如何使用sed/awk或其他方法从文件中删除特定行?

如何使用sed/awk或其他方法从文件中删除特定行?,sed,awk,add,lines,Sed,Awk,Add,Lines,我有一个文件,可以拉入并推送到svn存储库。我需要在从存储库中提取时删除一个文件的一部分,并在推送到存储库时添加相同的部分。这将由“git svn fetch”和“git svn dcommit”完成相关问题: 我需要一个sed或awk脚本来删除和添加以下内容: GlobalSection(SubversionScc) = preSolution Svn-Managed = True Manager = AnkhSVN - Subversion Support for Visua

我有一个文件,可以拉入并推送到svn存储库。我需要在从存储库中提取时删除一个文件的一部分,并在推送到存储库时添加相同的部分。这将由“git svn fetch”和“git svn dcommit”完成相关问题:

我需要一个sed或awk脚本来删除和添加以下内容:

GlobalSection(SubversionScc) = preSolution
    Svn-Managed = True
    Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection
由此:

Global
    GlobalSection(SubversionScc) = preSolution
        Svn-Managed = True
        Manager = AnkhSVN - Subversion Support for Visual Studio
    EndGlobalSection
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Debug|Mixed Platforms = Debug|Mixed Platforms
        Debug|x86 = Debug|x86
        Release|Any CPU = Release|Any CPU
        Release|Mixed Platforms = Release|Mixed Platforms
        Release|x86 = Release|x86
    EndGlobalSection
EndGlobal
编辑: 使用awk,我可以这样做以获取文件的特定部分

awk -v RS='GlobalSection' '/SubversionScc/ {print RS$0 RS} ' file
我如何还原此文件以获取除此部分之外的所有其他内容? 我如何在之后添加此部分

Global
或之前

EndGlobal

在原始文件中?

使用sed提取特定节

$ sed -n -e '/GlobalSection(SubversionScc/,/EndGlobalSection/p' yourfilename > yoursvnsection
$ cat yoursvnsection
    GlobalSection(SubversionScc) = preSolution
        Svn-Managed = True
        Manager = AnkhSVN - Subversion Support for Visual Studio
    EndGlobalSection
并使用sed将该文件读回

$ sed '/^Global$/ r yoursvnsection ' < yourfilename
Global
    GlobalSection(SubversionScc) = preSolution
        Svn-Managed = True
        Manager = AnkhSVN - Subversion Support for Visual Studio
    EndGlobalSection
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Debug|Mixed Platforms = Debug|Mixed Platforms
        Debug|x86 = Debug|x86
        Release|Any CPU = Release|Any CPU
        Release|Mixed Platforms = Release|Mixed Platforms
        Release|x86 = Release|x86
    EndGlobalSection
EndGlobal
$sed'/^Global$/r yoursvnsection'
如何提取和删除该节?不要管自己:$sed-e'/GlobalSection(SubversionScc/,/EndGlobalSection/d'original>originalWithoutSection