« August 2006 | Main | October 2006 »

September 2006 Archives


September 21, 2006

Inline editing with sed

This is going to be installment one of quite a few little tricks and tips that I never seem to remember, and consequently alsways end up having to go out an research again. Hence, I'll now be blogging these little gems so they are in one place.

Sed is very useful for editing a stream (i.e. a file) on the fly. The most common thing I use it for is in a script in order to replace a setting in a file.

sed -e '/foo/s//bar/g' - replace all instances of foo (a regex) with bar. Note that the -e is not needed if there is only one "script" to process.

Update - Thanks to mat (see comments) for pointing out my fat fingering - sed -e '/foo/s/bar//g'

Found this useful? Then Digg It.

September 24, 2006

Iterating a file using a basic for loop in bash

Another one I always use - doing some command over every line of a file:

for i in `cat foo.txt`; do echo $i; done

Nice and simple, but works a treat.

Found this useful? Then Digg It.


About September 2006

This page contains all entries posted to justinclarke.com in September 2006. They are listed from oldest to newest.

August 2006 is the previous archive.

October 2006 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.36

Valid XHTML 1.0!