Find the answer to your Linux question:
Results 1 to 2 of 2

Thread: substr pos?

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    substr pos?


    I've been looking all over trying to find an example of how to get the position of a substr in a string

    ex

    var="hello world"

    i want to find out what the index of "lo w" is

    all i can find online is how to slice from a string, but not return the actual position

  2. #2
    Quote Originally Posted by colfaxrev View Post
    I've been looking all over trying to find an example of how to get the position of a substr in a string

    ex

    var="hello world"

    i want to find out what the index of "lo w" is

    all i can find online is how to slice from a string, but not return the actual position
    Hi,

    Can you use awk to do it? If so, try:
    Code:
    var='hello world'
    str='lo w'
    awk -v a="$var" -v b="$str" 'BEGIN{print index(a,b)}'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •