Using Find & Sed to replace a pattern in multiple files…

Posted July 9th, 2007 by Daniel Nagle
Categories: Personal Notes

Of course this can be altered for use with any file type and regex.

    find . -type f -exec sed -i {} -e ‘s/pattern1/pattern2/g’ \;

– D.

Perl: Replacing every instance of a Regex found in multiple files…

Posted May 23rd, 2007 by Daniel Nagle
Categories: Technical

Simply use the following command;

perl -pi~ -e 's/regexp1/regexp2/' files

Where;

  1. regexp1 - Regular expression you are seeking.
  2. regexp2 - It's replacement.
  3. files - The files you wish this replacement to occur.

Vim: Counting the number of matches…

Posted May 23rd, 2007 by Daniel Nagle
Categories: Technical

A useful trick in Vim to return the number of matched expressions in a file;

let x=0 | g/regexp/let x=x+1
echo x

where regexp obviously is the regular expression (pattern) you wish to count.

Protected: A ripple in the pond….

Posted May 10th, 2006 by Daniel Nagle
Categories: Personal Notes

This content is password protected. To view it please enter your password below:

Protected: Stars shining down on me from afar

Posted February 9th, 2006 by Daniel Nagle
Categories: Personal Notes

This content is password protected. To view it please enter your password below:

Protected: The Clock has stopped ticking…

Posted January 24th, 2006 by Daniel Nagle
Categories: Personal Notes

This content is password protected. To view it please enter your password below:

Protected: Who Cares?

Posted September 23rd, 2005 by Daniel Nagle
Categories: Personal Notes

This content is password protected. To view it please enter your password below: