## The script filterre.pl

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57  #!/usr/bin/env perl # # Cannot use ✓ in the regex because it is used in the placeholder use strict; use strict; use IPC::Open3; use Getopt::Std; # declare the perl command line flags/options we want to allow my %options=(); getopts("r:", \%options); my $r = '\w+'; if (defined$options{r}) { $r = "$options{r}"; } my $first = shift;$| = 1; # make the current file handle (stdout) hot. This has the same effect as disabling buffering my @cmd = ($first); sub filter { # The regex match my$input = shift; my $pid = open3 my$stdin, my $stdout, '>&STDERR', @cmd; print$stdin "$input"; close$stdin; my $alloutput; while (my$line = readline $stdout) {$alloutput .= $line; } waitpid$pid, 0; my $exit =$? >> 8; return $alloutput; } foreach my$line ( ) { chomp( $line ); # Modify match and leave a placeholder to prevent changing the same thing # Repeat until no change while ($line =~ s/(?

### Example

Capitalise every word.

 1  ps -ef | head -n 10 | patm -r "\w+" "tr '[:lower:]' '[:upper:]'"
  1 2 3 4 5 6 7 8 9 10  UID PID PPID C STIME TTY TIME CMD ROOT 1 0 0 14:50 ? 00:00:02 /SBIN/INIT SPLASH ROOT 2 0 0 14:50 ? 00:00:00 [KTHREADD] ROOT 4 2 0 14:50 ? 00:00:00 [KWORKER/0:0H] ROOT 6 2 0 14:50 ? 00:00:00 [MM_PERCPU_WQ] ROOT 7 2 0 14:50 ? 00:00:02 [KSOFTIRQD/0] ROOT 8 2 0 14:50 ? 00:00:04 [RCU_SCHED] ROOT 9 2 0 14:50 ? 00:00:00 [RCU_BH] ROOT 10 2 0 14:50 ? 00:00:00 [MIGRATION/0] ROOT 11 2 0 14:50 ? 00:00:00 [WATCHDOG/0]