Using grep to only get lines with ip addresses

If you need to filter a file to only keep line containing only an ip address on the line, you can use grep with simple regular exception. An IP address is basically a list of exactly 4 numbers separated by dots. I assume here it’s encoded in decimal and each of these numbers thus has 1 to 3 digits:

  • decimal: [0-9] means any character between 0 and 9 (so 0,1,2,3,4,5,6,7,8 or 9).
  • 1 to 3 digits: …{1,3} matches 1 to 3 charactes. Note: we need to escape the curly braces: …\{1,3\}
  • separated by dots: Note: we need to escape the dots: \.
  • containing only an ip address on the line: ^…$ (^ = beginning of line, $ = end of line)

Combining this all gives us the following grep command:

grep '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' file.txt

Of course this will also match lines like 400.500.600.700 which is not a valid IP address but I guess the odds are you won’t have such a line in the file.

This is useful when you have some files where you know that when a line contains an IP address it is always at position X. You can then use awk (print $X;) to get this component of the line and remove all lines containing other data with this grep command.

Install WordPress on Mac OS X using AMPPS

After first using XAMPP, I moved to MAMP. And just noticed another interesting AMP tool called AMPPS. AMPPS stands for Apache, Mysql, PHP, Perl, Python and Softaculous auto-installer. This is basically an alternative to WAMP, MAMP and XAMPP for Windows and Mac OS X. It’s quite a new tool (version 1.0 was released in August 2011) but with quite frequent updates and it’s free !

It can be downloaded at There is a Windows and a Mac installer:

The Mac package is 212 MB (version 1.7). Even though I have a DSL 16000 connection (and can thus download from other sites up to 1.8 MB/s), it took me about an hour until I was ready to install it:

Installing it will take up 676.5 MB of your harddrive. This is quite a lot but it does include 264 scripts to install software like WordPress, Joomla, Drupal, Typo3, phpBB, MediaWiki, SquirrelMail, Roundcube, Mantis Bug Tracker, osTicket, Zend Framework, CakePHP, phpMyAdmin, jQuery and Dojo. It can also update them all automatically (but you can turn it off).

When you start the app, you’ll first see the control center. You can start Apache and MySQL there:

You can also click on one of the other tabs to get access to configuration files or log files.

After starting Apache, you can click on the admin icon in the lower right corner. This will open the administration page of AMPPS. When you then click on Software, you’ll see that the WordPress installation script is part of the package:

Now in order to install an instance of WordPress, you need to go back to the AMPPS control center and click “Local Web” icon (in the lower left corner). If will open a web page. There choose blog on the left hand side and then WordPress:

When you click on the install button, you’ll see the following page allowing to configure the usual installation parameters of WordPress:

Click install after you’ve entered the required data.

After a short time, it’s done installing:

And you can start working with your local WordPress installation.

Installing WordPress in MAMP or XAMPP isn’t that difficult but AMPPS really beats them both regarding ease of installation !

Reverse lookup

The Domain Name System supports not only the resolution of domain names (e.g. to IP addresses (e.g. 85.213.318.24), but also the reverse direction, using so-called reverse lookups.

For a reverse lookup, the IP address (e.g. 85.213.318.24) is divided into its components in reversed the order (e.g. 24.318.213.85). Then, the string “” is added to it (e.g.

The obtained identifier can then be used to perform a usual DNS query but for a PTR record (not for an A record). The PTR record contains a reference (pointer) to another DNS entry (to the address corresponding to the domain name).

This query can be performed with dig:

# dig ptr


An easier way (without computing the reverse lookup string):

# dig -x 85.213.318.24


or just use the host command:

# host 85.213.318.24 domain name pointer

Additionally, if you want to see whether a changed record has been propagated to a given Name Server, you can use nslookup:

# nslookup
> server
Default server:
> set q=ptr

Non-authoritative answer: name =

Authoritative answers can be found from:

> exit

The “server” command basically says to use another Name Server. “set q=ptr” sets to the query type to PTR.

Keyboard shortcuts in Mac OS X applications

These shortcuts work in most Mac OS X applications. 

Window and Application Control

cmd-tab to switch between currently running applications.
cmd-shift-tab to switch in the other direction
cmd-Q to exit the current application
alt-cmd-esc to open the “Force Quit…” dialog
cmd-W to close the current window of an application
cmd-< switch between the currently open windows of an application
shift-cmd-> to switch the other way
cmd-H to hide the current application and all associated windows in the Dock
cmd-, to open the settings window (in most applications)
cmd-. to abort (can be used usually in dialog boxes)

File Operations

cmd-N to open a new blank document
cmd-O to open an existing document
cmd-S to save the current document
cmd-shift-S to save the current document as …
cmd-P to print the current document


cmd-Z to undo the last editing function.
shift-cmd-Z to redo the last changes.
cmd-C to copie the selected content in the buffer (copy).
cmd-X to move into a buffer the selected content (cut).
cmd-V to move the content contained in the buffer into the current document (paste).
cmd-A to select the entire contents of the document


I wrote some time ago a post about how to install WordPress on Mac OS X.  I used XAMPP as a basis. But currently I’m using MAMP to host wordpress. 

XAMPP and MAMP are both quite similar. Both of them are self contained so neither touches the default OS X Apache/PHP installation. Both are extremely easy to install. Neither require any command line commands to setup. So both they can safely be tested and removed. You may even install both but you may only run one of them at a time (unless you edit the httpd.conf file for either XAMPP or MAMP and change the port it listens to).

Lately, MAMP seems to get updated more regularly, looks a little more mac-like, has a Dashboard Widget and works without administrator privileges.

On the other hand, XAMPP has many extensions built-in. Also XAMPP components can be started from a GUI or from the command line. MAMP requires the use of the GUI to start/stop it but its GUI does provide a configuration UI (e.g. where the ports can be set).

Conclusion: I’d say MAMP is still the better choice for web designers or PHP programmers who just want to run WordPress or Joomla and make settings using a graphical user interface. If  extensive configuration options is a must, you should consider giving XAMPP a try.

Install WordPress on Mac OS X

In this post, I’ll explain how to install WordPress locally on a Mac OS X machine.

First you’ll need to download the following:

XAMPP is an Apache distribution containing MySQL, PHP and Perl. It makes it much easier to install them. The Mac OS X package can be downloaded from here.

After downloading it, open the dmg archive and just drag the XAMPP folder to the Application folder to install it.

XAMPP will host our web folder and using the XAMPP console, we’ll be able to start/stop Apache HTTPd and MySQL.

First let’s start Apache HTTPd and MySQL:

Go to the Application folder, open the XAMPP folder and start “XAMPP Control”:

Now start both Apache and MySQL.
When starting Apache, you might be asked to authenticate. This will be required everytime you start or stop Apache.
If starting Apache fails, you’ll need to open the system preferences (Apple-Menu / System Preferences…) and choose Sharing (in Internet & Wireless) and disable Web sharing:

You should then be able to start the Apache web server.
If you get a message stating it wasn’t possible to start MySQL because it’s already running, you will need to either uninstall existing installations of MySQL or not have them start automatically. Here’s what I did on my system in order to do it:

ps -Af | grep sql | grep -v grep | awk '{ print $2; }' | xargs sudo kill -9

This will kill all running instances of MySQL.
Then I’ve edited /etc/hostconfig and removed the line MYSQLCOM=-YES-
Then the following:

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*

After that I was able to start MySQL from the XAMPP console.


Open phpMyAdmin which is part of XAMPP: http://localhost/phpmyadmin

There you need to create a database in MySQL for WordPress using the following settings:

After clicking Create, the database you need for wordpress will be created.

Now you need to deploy WordPress in XAMPP:
Download WordPress from
Extract the file (double-click) and copy the wordpress directory to /Applications/XAMPP/htdocs:

Now you need to update the configuration of WordPress to connect to our MySQL database. Open /Applications/XAMPP/htdocs/wordpress/wp-config.php and make the following changes:

Now you just need to open the installation of WordPress by going to the following URL: http://localhost/wordpress/wp-admin/install.php