Bash strings handling Examples
Recently I found some difficulty performing some string handling in shell script especially in bash.Even If I google for any string handling in shell script, I am bombarded with a lot of stuff but with tools like awk, perl, sed, python but very rarely in bash. So I thought it would be good to have useful string handling at one place. Below are some use case I would like to show:
- Length of a string.
- Substring from a particular position till the end.
- Substring from one position to another inside the same string.
- Delete a shortest substring(if exists) from front of a string.
- Delete a shortest substring(if exists) from back of a string.
- Delete a longest substring(if exists) from front of a string.
- Delete a longest substring(if exists) from back of a string.
- Find and Replace single match
- Find and Replace all match
Length of a string
0 comments: