From owner-freebsd-questions@FreeBSD.ORG Wed Aug 24 16:52:55 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B0CC416A41F for ; Wed, 24 Aug 2005 16:52:55 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.95]) by mx1.FreeBSD.org (Postfix) with ESMTP id E4B8943D49 for ; Wed, 24 Aug 2005 16:52:54 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from orion.daedalusnetworks.priv (aris.bedc.ondsl.gr [62.103.39.226]) by kane.otenet.gr (8.13.4/8.13.4/Debian-1) with SMTP id j7OGqq8a010081; Wed, 24 Aug 2005 19:52:52 +0300 Received: from orion.daedalusnetworks.priv (orion [127.0.0.1]) by orion.daedalusnetworks.priv (8.13.4/8.13.4) with ESMTP id j7OGqqBq000875; Wed, 24 Aug 2005 19:52:52 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by orion.daedalusnetworks.priv (8.13.4/8.13.4/Submit) id j7OGqpFH000874; Wed, 24 Aug 2005 19:52:51 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) X-Authentication-Warning: orion.daedalusnetworks.priv: keramida set sender to keramida@ceid.upatras.gr using -f Date: Wed, 24 Aug 2005 19:52:51 +0300 From: Giorgos Keramidas To: antenneX Message-ID: <20050824165251.GA855@orion.daedalusnetworks.priv> References: <20050824130412.GB877@orion.daedalusnetworks.priv> <000801c5a8ca$aca01680$0200000a@SAGEAME> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000801c5a8ca$aca01680$0200000a@SAGEAME> Cc: freebsd-questions@freebsd.org Subject: Re: Script help using "cut" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Aug 2005 16:52:55 -0000 On 2005-08-24 11:41, antenneX wrote: >Giorgos Keramidas wrote: >> sed -e 's/)[[:space:]]*$//' -e 's/^.*@//' >> >> or you can use as complex regular expressions as necessary to cut >> specific parts of the line: >> >> sed -e 's/^.*@\([^)]*\))[[:space:]]*$/\1/' > > In fact, my very next script line uses sed(1) to add the TAB and the > RHS to the sendmail access file: > sed 's/$/ REJECT/g' tmpfile >> /etc/mail/access > > I'll bet my line could be incorporated with yours. Sure. It's probably also a good idea to use mv(1) with a temporary file residing under /etc/mail too, to make sure the update to the access map is as close to being an ``atomic operation'' as possible: % accesstmp=`mktemp /etc/mail/access.tmp.XXXXXX` % if [ -z "${accesstmp}" ]; then % exit 1 % fi % % ( cat /etc/mail/access ; % awk '{whatever else here}' tmpfile | \ % sed -e 's/^.*@\([^)]*\))[[:space:]]*$/\1 REJECT/' ) > "${accesstmp}" % if [ $? -ne 0 ]; then % exit 1 % fi % mv "${accesstmp}" /etc/mail/access % cd /etc/mail && make access.db