For one-line strings, the GNU implementation of wc ashas a -L (a.k.a. --max-line-length) option that does exactly what you're looking for (except the control chars).
--max-line-length is GNU only. FreeBSD also have a -L but docs says it returns number of characters, and my tests show number of bytes.
Stéphane Chazelas
- 584.6k
- 96
- 1.1k
- 1.7k