Skip to Content
Asterisk: The Future of Telephony, 2nd Edition
book

Asterisk: The Future of Telephony, 2nd Edition

by Jim Van Meggelen, Jared Smith, Leif Madsen
August 2007
Intermediate to advanced
608 pages
20h 33m
English
O'Reilly Media, Inc.
Content preview from Asterisk: The Future of Telephony, 2nd Edition

Name

CUT — Cuts a string based on a given delimiter

Synopsis

CUT(varname,char-delim,range-s)

CUT() works in a similar manner to the cut(1) Unix command-line tool, and is, in fact, designed based upon that tool.

In the dialplan, you may specify character offsets to select a substring of a variable based purely on the uniform length of characters (namely 1). CUT() is designed to help you work with data that may have multiple, variable-length sections, divided by a common delimiter.

The most common case is the name of a channel, which is composed of two parts, a base name and a unique identifier (e.g., SIP/tom-abcd1234 or SIP/bert-1a2b3c4d). CUT() may be used to trim the unique identifier, no matter how long the base name may be:

; Trim the unique identifier from the current channel name
exten => 123,1,Set(chan=${CUT(CHANNEL,-,1)})

varname is the name of the variable that will be operated on. Note that CUT() operates on the name of a variable, rather than upon the value of a variable. CUT() is somewhat unique in this regard.

char-delim is the character that will serve as the delimiter ('-' is the default)

range-spec allows you to define which fields are returned. The range-spec can be specified as a range with - (e.g., 1-3) or a group of ranges and field numbers by separating each with & (e.g., 1&3-4). Note that if multiple field numbers are specified, the resulting value will have its fields separated by the same delimiter.

Tip

range-spec uses a 1-based offset. That is, the first field is field ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Asterisk: The Future of Telephony

Asterisk: The Future of Telephony

Jim Van Meggelen, Jared Smith, Leif Madsen
Switching to VoIP

Switching to VoIP

Theodore Wallingford

Publisher Resources

ISBN: 9780596510480Errata Page