Bash SubstringIn 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." SyntaxThe 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: where, 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 StartingOutput ![]() Example 2: To Extract from Specific Character onwardsOutput you on Javatpoint. Here, end of the string is considered as the end of the substring. Example 3: To Extract a Single CharacterOutput y Example 4: To Extract the specific characters from lastOutput Javatpoint. ConclusionIn this topic, we demonstrated how to extract a substring from a string in bash scripting with different types of scenarios and examples.
Next TopicBash Concatenate String
|