2011-03-14 6 views
0

J'ai un fichier que je tire et que je pousse dans un dépôt svn. J'ai besoin de supprimer une partie d'un fichier tout en tirant du dépôt et ajouter la même partie quand je pousse vers le référentiel. Cela se fera par 'svn git fetch' et 'git svn dcommit' La question connexe: How to setup gitattributes to filter part of a file?Comment supprimer des lignes spécifiques du fichier avec sed/awk ou autre chose?

je besoin d'un script sed ou awk pour supprimer et ajouter ceci:

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

De ceci:

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: Avec awk je peux faire pour obtenir la partie spécifique du fichier

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

Comment puis-je revenir à cela pour obtenir tout le reste sauf cette partie? Et comment puis-je ajouter cette partie après

Global 

ou avant

EndGlobal 

dans le fichier d'origine?

+0

http://en.wikipedia.org/wiki/Finite-state_machine –

Répondre

1

Utilisez sed pour extraire une section particulière.

$ 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 

Et utiliser sed pour lire ce fichier avant.

$ 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

Comment puis-je extraire et supprimer la section? – mrt181

+0

Nevermind géré moi-même: $ sed -e '/ GlobalSection (SubversionScc /,/EndGlobalSection/d' original> originalWithoutSection – mrt181

Questions connexes