Networker

Re: [Networker] nsradmin regular expressions

2002-09-26 18:13:24
Subject: Re: [Networker] nsradmin regular expressions
From: "Chad R. Larson" <clarson AT ELDOCOMP DOT COM>
To: NETWORKER AT LISTMAIL.TEMPLE DOT EDU
Date: Thu, 26 Sep 2002 15:13:13 -0700
At 02:56 PM 9/26/02 , Tim Mooney wrote:
The problem is that there's no way to do backreferences that I'm aware of,
so in the example you show above, your *entire* owner notification will be
replaced with `jimuser...', rather than just the one part of the RE that
your selection matched.

You backreference by enclosing the part you want to re-use in escaped
parentheses, and then use an escaped number to match the n'th sub-expression.

Check out the sed statement near the bottom of the attached shell script
for an example.

----- cut -----
#!/bin/sh
# $Id: renumber.sh,v 1.4 2000/11/24 22:02:25 chad Exp $

# Renumber images consecutively.
# Used to fixup uploads from the digital camera.

# Takes two arguments, first a prefix describing the
# files to be renumbered, second a prefix to be applied
# to the renumbered files.
#  IE: "renumber MVC Christmas"
# It will accept a verbose switch.

LS=/bin/ls
PRINTF=/usr/bin/printf

if [ $1 = "-v" ] ; then
    VERBOSE=true
    shift
fi

if [ $# -ne 2 ] ; then
  echo "Usage: $0 [-v] <before> <after>"
  exit 1
fi

PRE=$1
NAME=$2

FILES=`${LS} ${PRE}*.jpg ${PRE}*.JPG ${PRE}*.mpg ${PRE}*.MPG 2> /dev/null`
if [ -z "${FILES}" ] ; then
    echo "No files found."
    exit 2
fi

COUNT=0
for FILE in ${FILES} ; do
    COUNT=`expr ${COUNT} + 1`
    TYPE=`echo ${FILE} | sed -e 's/^..*\(\..*$\)/\1/'`
    NEW=`${PRINTF} '%s-%03d%s' ${NAME} ${COUNT} ${TYPE}`
    if [ ${VERBOSE} ] ; then
        echo "${FILE} becomes ${NEW}"
    fi
    mv ${FILE} ${NEW}
done
----- uncut -----
        -crl
--
Chad R. Larson (CRL22)    chad AT eldocomp DOT com
  Eldorado Computing, Inc.   602-604-3100
     5353 North 16th Street, Suite 400
       Phoenix, Arizona   85016-3228

--
Note: To sign off this list, send a "signoff" command via email
to listserv AT listmail.temple DOT edu or visit the list's Web site at
http://listmail.temple.edu/archives/networker.html where you can
also view and post messages to the list.
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

<Prev in Thread] Current Thread [Next in Thread>