A question for the AWK wizards

Parv parv at pair.com
Tue Jul 25 14:53:16 UTC 2006


in message <04E232FDCD9FBE43857F7066CAD3C0F11EEAFA at svmailmel.bytecraft.internal>,
wrote Murray Taylor thusly...
>
> # generate the sms message
> # the awk code forces the message to be < 160 chars
...
>    tmpfile=`mktemp -t sms`
>    echo ${phone} >> ${tmpfile}
>    ${AWK} '{ printf "%-0.159s", $0 }' >> ${tmpfile} << EOF2
> `echo $msg`
> EOF2

As it is, any line longer than 159 characters will just overflow.
You need to use substr() not awk to shorten a line.  Even after that
modification, that won't solve your actual problem as the awk script
will just shorten EACH line (when record separator is newline), not
the whole output.

There are ports which seems to do what you want to do.


  - Parv

-- 



More information about the freebsd-questions mailing list