title: Ubuntu, Bash, awk, regular expressions -> find all the [numbers] in text file and print them
body: <p>I want to find each number in "[]" brackets, and print all their appearances (line numbers) in text file.</p>
  
  <p>For example I got text file like this:</p>
  
  <pre><code>texttexttext[1] textetxtetete[2]
  [1]textextetetete[3]
  texttexttext[2]
  texttexttext
  text[3]text[1]
  </code></pre>
  
  <p>And the output should be this :</p>
  
  <pre><code>[1] = lines : 1 2 5
  [2] = lines : 1 3
  [3] = lines : 2 5
  </code></pre>
  
  <p>This is what I've done so far :</p>
  
  <pre><code>#!/bin/bash
  cat $1 | awk -F'[/[/] ]' '{     #[] as file separators
  for (i=1;i&lt;=NF;i++)             #for every part of line
    {
    if ($i ~ "[0-9]+")            #if its number
      {
        #save it somehow
      }
  }}'
  </code></pre>
  
  <p>The script finds the desired numbers, but now I want to save it, and its line number (NR variable) in some simple way. Should I try something with arrays? I would need at least two-dimensional arrays, but they are a bit problematic in bash. Is there any better way to do it?</p>