开发者

How to remove specific lines from file with sed/awk or something else?

I have a file that i pull and push to a svn repository. I need to remove part of one file while pulling from the repository and add the same part when i push to the repository. This will be done by 'git svn fetch' and 'git svn dcommit' The related question: How to setup gitattributes to filter part of a file?

I need an sed or awk script to remove and add this:

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

From this:

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

EDIT: With awk i can do this to get the specific part of the file

awk -v RS='GlobalSection' '/SubversionScc/ {print RS$0 RS} ' file

How do i revert this to get everything else except this part? And how do i add this part after

Global

or before

EndGlobal
开发者_如何学Go

in the original file?


Use sed to extract a particular section.

$ 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

And use sed to read that file back in.

$ 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜