Perl one liners

Simple replace

How to edit a bunch of files with one simple command:

perl -pi.bak -e 's/bad/good/' ~/files.*.conf

Replaces occurence of 'bad' with 'good' in all matching files and creates a .bak copy of the modified files.

Replace serial number in zone files:

perl -pi.bak -e 's/200\d\d\d\d\d\d\d/2006053001/' db.domain.tld

Small scripts

#!/usr/bin/perl -w
# Quick'n dirty replace script
# 2007-06-21/TB
use strict;
if (scalar @ARGV < 2) {
        die "Usage: $0 searchstring replacestring\n";
my $suche = shift @ARGV;
my $ersetze = shift @ARGV;
while (<>) {
linux/perl.txt · Last modified: 2009-04 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready