awk extract multiple groups from each line

后端 未结 4 2208
盖世英雄少女心
盖世英雄少女心 2020-12-06 12:51

How do I perform action on all matching groups when the pattern matches multiple times in a line?

To illustrate, I want to search for /Hello! (\\d+)/ an

4条回答
  •  一向
    一向 (楼主)
    2020-12-06 12:54

    This is gawk syntax. It also works for patterns when there's no fixed text that can work as a record separator and doesn't match over linefeeds:

     {
         pattern = "([a-g]+|[h-z]+)"
         while (match($0, pattern, arr))
         {
             val = arr[1]
             print val
             sub(pattern, "")
         }
     }
    

提交回复
热议问题