deletestring - UDM Command

Syntax

deletestring variable_name pos=position |{startseq=sequence [startseqnum=number]} length=length |{endseq=sequence [endseqnum=number]} [case=yes|no]

Description

The deletestring command removes a substring from an existing string.

The first parameter, VARIABLE_NAME, is the name of an existing variable.

The beginning of the sequence to be deleted is indicated by either its starting position (one-based index, using the pos parameter) or as immediately following a particular occurrence of a character sequence (startseq specifies the sequence and the optional startseqnum specifies the occurrence number).

The end of the substring is determined by either specifying the length of the substring using the length parameter or giving a sequence that indicates the end of the substring (endseq specifies the ending sequence and the optional endseqnum specifies the occurrence number).


<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="33cd4a58-e72a-43bd-b885-47ae6da84d85"><ac:parameter ac:name="">1154078</ac:parameter></ac:structured-macro> The optional case parameter specifies whether the comparisons of the sequences are case-sensitive (yes) or case-insensitive (no). [Default is no.]

The _lastrc.message built-in variable will contain:

  • NO_MATCH if start or end sequences were specified and could not be matched
  • INVALID_VALUE if the starting position or length are out of range
  • SUCCESS if a sub-string was successfully deleted

Parameters

Parameter

Description

variable_name

Name of an existing variable.

pos=position

Starting position of sequence to be deleted (one based index).

startseq=sequence

Starting position of sequence to be deleted (following a specific character sequence).

startseqnum=number

Occurrence number of starting position of sequence to be deleted (following a specific character sequence).

length=length

Length of the substring to be deleted.

endseq=sequence

Ending position of sequence to be deleted (preceding a specific character sequence).

endseqnum=number

Occurrence number of ending position of sequence to be deleted (preceding a specific character sequence).

case=yes | no

Indicates whether or not the comparisons of the sequence are case-insensitive.

Default is no.

Examples

The following examples illustrate how deletestring is used starting with a sample string called mystring with an initial value of This is not just some sample text:

set mystring="This is not just some sample text"
deletestring mystring pos=8 length=4*=
echo "$(mystring)"
This is just some sample text

set mystring="This is not just some sample text"
deletestring mystring startseq=" " startseqnum=2 endseq=" "
echo "$(mystring)"
This is just some sample text

set mystring="This is not just some sample text"
deletestring mystring startseq=" " startseqnum=2 length=21
echo "$(mystring)"
This is text