Bash substring, prefix, suffix

Substring
$ a=teststring
$ echo ${a:2:5}
ststr

Remove prefix (#)
$ a=text_test.txt
$ echo ${a#*_}
test.txt

Remove suffix (%)
$ a=text_test.txt
$ echo ${a%.txt}
text_test

Leave a Reply

Your email address will not be published. Required fields are marked *