Date Tags sed / unix

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 powered by Disqus

About Yusuke Tsutsumi
I work at Zillow. I focus on tools and services for developer productivity, including build and testing.

My other interests include programming language design, game development, and learning languages (the non-programming ones).