2011-03-14 48 views
0

我有一个文件,我拉和推到svn存储库。我需要从存储库中删除一个文件的一部分,并在我推送到存储库时添加相同的部分。这将完成“混帐SVN取”和“混帐SVN dcommit”的相关问题:How to setup gitattributes to filter part of a file?如何使用sed/awk或其他东西从文件中删除特定的行?

我需要一个awk或者sed脚本,删除和补充一点:

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 

在原来的文件中添加这部分?

+0

http://en.wikipedia.org/wiki/Finite-state_machine – 2011-03-14 08:19:01

回答

1

使用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 
+0

我如何提取并删除部分? – mrt181 2011-03-14 12:20:49

+0

Nevermind自己管理它: $ sed -e'/ GlobalSection(SubversionScc /,/ EndGlobalSection/d'original> originalWithoutSection – mrt181 2011-03-14 12:34:30