Using sed

For a couple of days now i’ve been pondering about posting something about my love for GNU text-utilities but never got round to it. A couple of minutes ago i read Phil Windley’s Using Grep and Find post so here is a one-liner that shows how you can add a reference to a msbuild target file to all csproj files in a given folder:

find -name *.csproj -exec sed -i -e '#^</Project>$#  <Import Project="X:\\BuildTasks\\Corp.targets" />\r\n</Project>' {} \;

Or if you are frustrated with System.Diagnostics.CodeAnalysis.SuppressMessageAttributes and want to remove them from all your cs files:

find -name *.cs -exed sed -r -i -e  's#\[.*?SuppressMessage.*?\]##' {} \";

This entry was posted on Thursday, March 5th, 2009 at 21:36 and is filed under C#, Free Software. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply