Finding a sub-string with indices from both ends

Ankit

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?

choroba

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Recursively finding indices of a string

From Dev

Recursively finding indices of a string

From Dev

How to get the sub-string starting from specified position till the string ends in smarty?

From Dev

Adding equal amount of whitespace to both ends of string

From Dev

VBA paste from Excel to Word ends sub

From Dev

Finding the repeating sub string in a big string

From Dev

finding the a sub string at the end of a string in a sql query

From Dev

Finding the children of the sub-sub-category from a sub-category

From Dev

Finding the children of the sub-sub-category from a sub-category

From Dev

Python regex finding sub-string

From Dev

Finding Substring from a String

From Dev

Finding sub intervals from interval data frames

From Dev

How to remove single and double quotes at both ends of a string

From Dev

Finding the number of matching letters in two different string at the same indices

From Dev

RegEx for removing non ASCII characters from both ends

From Dev

Finding indices of items from a list in another list even if they repeat

From Dev

Finding the indices of all matches in a string, appending search term and indices to a dictionary.

From Dev

Drawline offset at both ends

From Java

Check if string ends with one of the strings from a list

From Dev

Finding a String from JSON in Dart

From Dev

Finding a string from list of objects

From Dev

Finding Zip number from String

From Dev

finding words from an array, in a string

From Dev

Finding indices of elements in vector

From Dev

Finding all indices by ismember

From Dev

Finding all indices by ismember

From Dev

Remove duplicates (both lines) and duplicate only based on a sub-string

From Dev

Parsing JSON from a (sub)string

From Dev

Parsing JSON from a (sub)string

Related Related

  1. 1

    Recursively finding indices of a string

  2. 2

    Recursively finding indices of a string

  3. 3

    How to get the sub-string starting from specified position till the string ends in smarty?

  4. 4

    Adding equal amount of whitespace to both ends of string

  5. 5

    VBA paste from Excel to Word ends sub

  6. 6

    Finding the repeating sub string in a big string

  7. 7

    finding the a sub string at the end of a string in a sql query

  8. 8

    Finding the children of the sub-sub-category from a sub-category

  9. 9

    Finding the children of the sub-sub-category from a sub-category

  10. 10

    Python regex finding sub-string

  11. 11

    Finding Substring from a String

  12. 12

    Finding sub intervals from interval data frames

  13. 13

    How to remove single and double quotes at both ends of a string

  14. 14

    Finding the number of matching letters in two different string at the same indices

  15. 15

    RegEx for removing non ASCII characters from both ends

  16. 16

    Finding indices of items from a list in another list even if they repeat

  17. 17

    Finding the indices of all matches in a string, appending search term and indices to a dictionary.

  18. 18

    Drawline offset at both ends

  19. 19

    Check if string ends with one of the strings from a list

  20. 20

    Finding a String from JSON in Dart

  21. 21

    Finding a string from list of objects

  22. 22

    Finding Zip number from String

  23. 23

    finding words from an array, in a string

  24. 24

    Finding indices of elements in vector

  25. 25

    Finding all indices by ismember

  26. 26

    Finding all indices by ismember

  27. 27

    Remove duplicates (both lines) and duplicate only based on a sub-string

  28. 28

    Parsing JSON from a (sub)string

  29. 29

    Parsing JSON from a (sub)string

HotTag

Archive