Category: Linux

Linux: Read / dump contents of DMB file created with httxt2dbm

Berkley DB (DBM) files seem easy to create, but hard to read/manage. The most common task I can think of wanting to do on a database file is to dump or display it’s contents. And there’s no easy or straight forward way to do this (at least not that I found).

We were creating DBM files (from text files) for use by Apache/mod_rewrite using the httxt2dbm utility. If you create “file.dbm” it actually creates “file.dbm.pag” and “file.dbm.dir”.

To output the contents of the DBM file(s), Perl comes to the rescue. A colleague of mine wrote this after we searched the net for a working script and failed to find one. I’m sharing it in hopes someone will find it useful.

# /path/to/ /path/to/file.dbm
use SDBM_File;
use strict;

my ($name) = @ARGV;
die "Missing DBM name.\n" unless $name;
my %map;
tie( %map, 'SDBM_File', $name, 'O_RDONLY', 0644 ) || die "Can't open DBM file\n"; for my $k (sort(keys %map)) {
  # value is terminated by a null character, but the hash value contains cruft after that
  # so cut off the value at the first \0
  my @v = split("\0",$map{$k});
  print $k, "\t", $v[0], "\n";
untie %map;

FTP files from Unix to Windows and get double lines

Sometimes, but not always, you’ll download a file from a Unix server to your Windows workstation, only to find that all line breaks have been doubled! This consistently happens to me when downloading WordPress theme files that have been edited using the WordPress theme editor (thus modified by the server).

The FTP client can have its default transfer type set to ASCII, Binary, or Auto. The problem seems to be resolved by setting it to Binary. If that doesn’t work, try ASCII.

But maybe the damage has already been done. Maybe it’s been downloaded and uploaded multiple times, so now the extra lines are part of the real file. Many IDEs have a tool to apply source formatting. For example in Dreamweaver, Commands->Apply Source formatting.

There are many ways/tools to remove blank lines. A quick and easy online tool may be just what you need: