bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] Search for all the occurrences of the pattern in the string


From: Ehsan Hajiramezanali
Subject: [bug-gawk] Search for all the occurrences of the pattern in the string
Date: Thu, 26 May 2016 17:18:46 -0500

Hi, 

I want to search for all the occurrences of the pattern in a string.
However, 'match' only returns the first occurrence of the string.

I have the following approach to handle it:

For example, I want to extract the location of 'Hello!'.
~~~

{

  pattern = "(Hello!)"

  while (match($0, pattern, arr))

  {

    print arr[1], arr[1, "start"]

    sub(pattern, "") 

  }

}

~~~

However, it is not useful when the input string is long.
Would you please let me know that there is a better way to get all matches by awk instead of applying loops?

Thanks in advance.
Ehsan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]