From owner-freebsd-questions@FreeBSD.ORG Tue Jul 25 13:37:10 2006 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 5FEA416A4DA for ; Tue, 25 Jul 2006 13:37:10 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9E30643D45 for ; Tue, 25 Jul 2006 13:37:09 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.pc (host5.bedc.ondsl.gr [62.103.39.229]) (authenticated bits=128) by igloo.linux.gr (8.13.7/8.13.7/Debian-1) with ESMTP id k6PDaXMI011187 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 25 Jul 2006 16:36:42 +0300 Received: from gothmog.pc (gothmog [127.0.0.1]) by gothmog.pc (8.13.7/8.13.7) with ESMTP id k6PDaS2h045539; Tue, 25 Jul 2006 16:36:28 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.pc (8.13.7/8.13.7/Submit) id k6PDaRCx045538; Tue, 25 Jul 2006 16:36:27 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Tue, 25 Jul 2006 16:36:27 +0300 From: Giorgos Keramidas To: Murray Taylor Message-ID: <20060725133627.GC43934@gothmog.pc> References: <04E232FDCD9FBE43857F7066CAD3C0F11EEAFA@svmailmel.bytecraft.internal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <04E232FDCD9FBE43857F7066CAD3C0F11EEAFA@svmailmel.bytecraft.internal> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-3.776, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.62, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-questions@freebsd.org Subject: Re: A question for the AWK wizards 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: Tue, 25 Jul 2006 13:37:10 -0000 On 2006-07-25 21:43, Murray Taylor wrote: > Hi all, > > I have a shell script which is called with an arbitrary message > argument. Punctuation excludes * ? & | > < chars. > > It processes it via an AWK command line 'script' and dumps the result > in a file for the SMS sender... > > Nice and simple. > > Except that the AWK script seems to duplicate the last character or > two in the message. Everything else in the 200 odd lines of shell > scripts surrounding this function run just fine, and this bit runs > too, but this tiny thing is _VERY_ annoying. > > The shell code is listed below. > > Please teach me what bit I missed .... (C and TCL are my forte, not > AWK) > ------------------8<------------------------------ > # sourced into other scripts that need to SMS > # !! 4 space indents, NOT tabs !! > # > # generate the sms message > # the awk code forces the message to be < 160 chars > sendsms() { > msg=$1 > > case ${sms_enable} in > [Yy][Ee][Ss]) > for phone in ${phonelist} > do > tmpfile=`mktemp -t sms` > echo ${phone} >> ${tmpfile} > ${AWK} '{ printf "%-0.159s", $0 }' >> ${tmpfile} << EOF2 > `echo $msg` > EOF2 > mv ${tmpfile} ${gsmspool_dir} > done > ;; > *) > ;; > esac > } The above has a weird construct which can be simplified a bit: | ${AWK} '{ printf "%-0.159s", $0 }' >> ${tmpfile} << EOF2 | `echo $msg` | EOF2 You can write this as: | echo "${msg}" | ${AWK} '{printf "%-0.159s", $0}' >> "${tmpfile}" Are you deliberately avoiding to append a newline character to the output of ${AWK} above? See the output of the two commands below, as it's filtered through hd(1) utility. | $ echo foo | awk '{ printf "%-0.159s", $0 }' | hd | 00000000 66 6f 6f |foo| | 00000003 | $ echo foo | awk '{ printf "%-0.159s\n", $0 }' | hd | 00000000 66 6f 6f 0a |foo.| | 00000004 | $ There is no problem with this part of the scripts you posted though. They should work as expected. I'd probably look elsewhere for a bug that causes the character duplication.