#!/bin/sh # # $Id: rename-strace-pids.sh,v 1.1 2005/11/18 11:46:58 andy Exp $ # # We've generated a bunch of output files with "strace -fF". # Naturally, the PID numbers are arbitrary and uninteresting. To make # it easier to compare these files with diff, we want to change all # the pids to consisent, uniform numbers. This script does that. # --atp@piskorski.com, 2005/11/18 01:51 EST n_pids=6 new_pids=(781 782 783 784 785 786) new_dir="new-strace" create_dir() { # Takes the path name of directory to create. Allows recursive # creation. If the file already exists, returns an error if it is a # normal file, does nothing if the file is a directory. return_code=0 if [ -f $1 ] then return_code=1 $ECHO "Error: A file '$1' already exists. Cannot create directory '$1'." elif [ ! -d $1 ] then mkdir -p $1 return_code=$? fi return $return_code } create_dir $new_dir if [ $? -ne 0 ] ; then exit $? fi for ff in "$@" do old_pids=`cat $ff | grep '\[pid[^]]*\]' | sed -e 's/\(\[pid[^]]*\]\).*/\1/g' | sort | uniq | sed -e 's/[^0-9]*//g'` cmd="cat $ff | sed" ii=0 for oo in $old_pids do cmd="${cmd} -e 's/${oo}/${new_pids[$ii]}/g'" ii=`expr $ii + 1` done if [ "$n_pids" -ne "$ii" ] ; then echo "ERROR: Number of new and old PIDs do not match for file: $ff" else eval $cmd > "${new_dir}/`basename $ff`" fi done