title: How to get the line number of a match?
body: <p>My aim is to get the line number ($lineof) of a string which matches a line in <code>/etc/crontab</code>.</p>
  
  <p>To give <code>0 8 * * * Me echo "start working please"</code> and get <code>this is the line number 13 from /etc/crontab</code>.</p>
  
  <p>Given this file <em>/tmp/crontab</em> :</p>
  
  <pre><code># /etc/crontab: system-wide crontab
  # Unlike any other crontab you don't have to run the `crontab'
  # command to install the new version when you edit this file
  # and files in /etc/cron.d. These files also have username fields,
  # that none of the other crontabs do.
  
  SHELL=/bin/sh
  PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  
  # m h dom mon dow user  command
  #
  0 17 * * * Me echo "end of work"
  0 8 * * * Me echo "start working please"
  1 3 2 4 2 Me ls -la
  </code></pre>
  
  <p>I do something like that for the moment:</p>
  
  <pre><code>cat /etc/crontab | grep -v "#" | grep "Me" &gt; /tmp/task.cron
  i=1
  while read -r content
  do
          line=$content
          # lineof=$LINENO
          nbline=${i}
          minute=$(echo "$line" | awk '{print $1}')  #0-59
          hour=$(echo "$line" | awk '{print $2}')    #0-23
          dom=$(echo "$line" | awk '{print $3}')     #1-31
          month=$(echo "$line" | awk '{print $4}')   #1-12
          dow=$(echo "$line" | awk '{print $5}')     #0-6 (0=Sunday)
          cmd=$(echo "$line" | awk '{$1=$2=$3=$4=$5=$6=""; print $0}')    #command
          cmd=$(echo "$cmd" | tr ' ' _)
          str=$str' '$nbline' "'$minute'" "'$hour'" "'$dom'" "'$month'" "'$dow'" "'$user'" "'$cmd'" '
          i=$(($i+1))
  done &lt; /tmp/task.cron
  </code></pre>
  
  <blockquote>
    <p><code>$nbline</code> give me the line of the content in <em>/tmp/task.cron</em></p>
    
    <p><code>$LINENO</code> give me the line of the current script (which execute the program)</p>
    
    <p>I want <code>$lineof</code> give me the number of the line in <em>/etc/crontab</em></p>
  </blockquote>