2011-03-14 49 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