Yusuke Tsutsumi

yusuketsutsumi

  • Home
  • Projects
  • About

Recent Posts


  • Automatic Package installation using ELPA in Emacs 24
  • Python Pet Peeves
  • Search and replace multi-line expressions with SED
  • WebPageTest and IE9
  • Getting Python2.5 to Build with sqlite3 and zlib on Ubuntu Natty 2.5

Coding


My focus is on implementing technologies for back-end preformance and test evaluation.

  • My Emacs Build
  • MySQL m4

Videos


Search and replace multi-line expressions with SED

10/26/2011 11:55pm | 2 Comments

Now here's an interesting problem: I wanted to do a recursive search and replace in unix, AND I wanted to do an expression that spans multiple lines. Here's what I came up with:
find ./ -type f | xargs sed -E -i -n
'1h;1!H;${;g;s/</fileSet>.*<fileSet>.*RevisionVersion.*
</fileSet>.*</fileSets>/</fileSet>n</fileSets>/g;p}'
There a lot of examples showing you how to do this. The first argument lists all files recursively. These are the piped to sed, which uses an inline search and replace (-i or --in-line), then using the expression '{}' which is then modified for multi-line expressions (1h;1!H;).
Comments
xmlrpc | 01/26/2012 09:02am
test_comment
Joon | 01/03/2012 01:12pm
I enjoy your blog a lot!
Leave a comment:



  • Coding
  • GitHub
  • StackOverflow
  • Contact
  • Email
  • Social
  • LinkedIn
  • Google+
Copyright 2011 Yusuke Tsutsumi, All rights reserved