Asterisk func cut


at least on asterisk 1.2.8 the parameters must be separated by "|" and not ","



  • varname: variable you want cut (and not a string - see Asterisk func passthru of Asterisk 1.8)
  • delimiter: defaults to -
  • fieldspec: number of the field you want (1-based offset), may also be specified as a range (with -) or group of ranges and fields (with &).


  • The delimiter must be a single character. When multiple characters are specified, only the first character is used.
  • To specify a comma or semicolon as a delimiter, escape it with a backslash: CUT(foo,\,,1)
  • When multiple fields are specified, they are joined back together using the delimiter specified.
  • Leaving off one end of the range will give you the full variable at the field and to the other end of the variable.
    • "CUT(somevar,,3-)" would give the 3rd field and everything past,
    • "CUT(somevar,,-2)" would give the 2nd field and everything before.
  • This command is most useful when dealing with fields that are variable width. For fixed width string processing, use the builtin variable substitution.
  • CUT is frequently used to trim the uniqueid section off a channel name. For instance, the channel name might be SIP/somehost-f387 and you might want to trim that to SIP/somehost.
  • This function replaces the application Cut, which is now deprecated.

The varname parameter must be a variable name, not a string value. This is unusual syntax. So:

exten => s,1,Set(foo=${CUT(bar,,2)}) ; This is correct syntax
exten => s,1,Set(foo=${CUT(${bar},,2)}) ; This is invalid syntax (unless bar contains the name of another variable)

Return value

Returns the resulting string.


exten => s,1,Set(foo=1-2-3-4-5)
exten => s,2,Set(foo=${CUT(foo,,1-3&5)})

foo is now set to 1-2-3-5

Cut a comma separated list:

exten => s,1,Set(myVar="one,two,three")
exten => s,2,Set(cutVar=${CUT(myVar,\,,1)})

cutVar is set to value 'one'

See also

  • Asterisk func FIELDQTY
  • Asterisk func ARRAY
  • Asterisk func POP: Removes and returns the last item off of a variable containing delimited text
  • Asterisk func SHIFT: Removes and returns the first item off of a variable containing delimited text
  • Asterisk func LISTFILTER as introduced with Asterisk 1.6.2: Remove elements from a set list (by name)
  • Asterisk func REPLACE as introduced with Asterisk 1.8
  • Asterisk func passthru: Literally pass the same argument back as its return value. The intent is to be able to use a literal string argument to functions that currently require a variable name as an argument. (Asterisk 1.8)
  • Asterisk variables

Created by: Corydon76, Last modification: Fri 15 of Jan, 2016 (03:59 UTC) by gavron
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+