Date: Tue, 25 Jul 2006 16:36:27 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Murray Taylor <MTaylor@bytecraft.com.au> Cc: freebsd-questions@freebsd.org Subject: Re: A question for the AWK wizards Message-ID: <20060725133627.GC43934@gothmog.pc> In-Reply-To: <04E232FDCD9FBE43857F7066CAD3C0F11EEAFA@svmailmel.bytecraft.internal> References: <04E232FDCD9FBE43857F7066CAD3C0F11EEAFA@svmailmel.bytecraft.internal>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2006-07-25 21:43, Murray Taylor <MTaylor@bytecraft.com.au> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060725133627.GC43934>