如何使用 sed/awk 或其他东西从文件中删除特定行?
我有一个文件,我将其拉取并推送到 svn 存储库。我需要在从存储库中拉取时删除一个文件的一部分,并在推送到存储库时添加相同的部分。这将通过 'git svn fetch' 和 'git svn dcommit' 完成相关问题: 如何设置 gitattributes 来过滤文件的一部分?
我需要一个 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
在原始文件的
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
in the original file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 sed 提取特定部分。
并使用 sed 读回该文件。
Use sed to extract a particular section.
And use sed to read that file back in.