In kind of a follow up to my previous post on using find and sed to search and replace multiple files, I found out something else.
I needed to find and replace something in every file, except for any files which had ".svn" in them. After struggling for a few fruitless minutes with -regex, I stumbled upon this example in the manual page:
find /sbin /usr/sbin -executable \! -readable -print
Search for files which are executable but not readable.
The \! allows us to invert the tests after it. Perfect! All we need to do is use -regex to do our excluding:
find . -type f \! -regex ".*\.svn.*"
And we can now search and replace in all files except those that have ".svn" in them:
find . -type f \! -regex ".*\.svn.*" -print0 | xargs -0 sed -i "s/foo/bar/"
Neat. Note that, again, -regex is a GNU find only construct.
Posted on November 10th, 2009 in linux, programming, shell scripting, sysadmin | No Comments »
I've released Templum v0.4.0
Templum is an extremely lightweight, simple yet powerful and fast templating engine for PHP. It re-uses the power of PHP itself for rendering templates, but provides additional features making it easier to write templating code. Rendering templates using Templum is very fast; it approximates native PHP rendering speed for include() statements.
This release features:
- Some small bug fixes
- Documentation updates
- The ability to include other templates in a template
Download instructions here.
Posted on November 10th, 2009 in libre software, php, programming, projects, website | No Comments »
I always kept a small Python script around for searching and replacing in Linux. Turns out that GNU sed has an inline edit mode which I didn't know about:
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
This makes searching and replacing in files as simple as:
find . -name "*.txt" -print0 | xargs -0 sed -i "s/foo/bar/"
This replaces all occurences of "foo" with "bar" in all the .txt files in or below the current directory.
Unfortunately, -i appears to be a GNU extension, so it won't work on *BSD or Solaris, probably.
Posted on November 9th, 2009 in linux, shell scripting, sysadmin | No Comments »
I have a laptop that travels with me to work as well as being used at home. I have a number of network CIFS mounts that I like to have available when I am at home, so I have them set to "auto" in /etc/fstab. [...] The problem is that when I shift locations, I need proper handling of those network mounts.
Handling network mounts on a very mobile laptop.
Posted on November 6th, 2009 in link, sysadmin | No Comments »