I am trying to extract a sub string with an starting index and index from the last
for example
val = "SUBSTRING"
|||||||||||||||||
12345678901234567
I need the string from start index = 8 and end index = -2 (length of sub string is variable of course)
I know its a very basic question but is there any direct way to do it using single command?
You can use parameter substring expansion:
string='val = "SUBSTRING"'
echo "${string:7:-1}"
The starting position is 7, as the numbering starts from 0.
If length evaluates to a number less than zero, [ ... ] it is interpreted as an offset from the end of the value of parameter rather than a number of characters, and the expansion is the characters between the two offsets.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments