In this topic, we have explained how to compute substring of a given string.
A substring is a sequence of characters within a string. Bash provides an option to extract the information from a string itself. You can extract the digits or a given string using several methods.
For example, "welcome you on Javatpoint." is a substring of "We welcome you on Javatpoint."
The command for the extraction of substring is a build-in bash command, and so it is very good to use for performance perspective.
The syntax of the substring extraction can be defined as:
Variable is the variable name that contains a string.
Note: Assigning length is optional. If length is not provided, then end of the string will be considered as the end of the substring.
Let's understand the concept of extracting a substring from the string with the help of some examples:
Example 1: To Extract till Specific Characters from Starting
Example 2: To Extract from Specific Character onwards
you on Javatpoint.
Here, end of the string is considered as the end of the substring.
Example 3: To Extract a Single Character
Example 4: To Extract the specific characters from last
ConclusionIn this topic, we demonstrated how to extract a substring from a string in bash scripting with different types of scenarios and examples.