Numbering lines matching the pattern using sed

前端 未结 6 1984
一生所求
一生所求 2021-02-01 06:59

I\'m writing the script that searches for lines that match some pattern. I must use sed for this script. This works fine for searching and printing matched lines:



        
6条回答
  •  心在旅途
    2021-02-01 07:47

    Switch to awk.

    BEGIN {
      ln=0
    }
    
    $0 ~ m {
      ln+=1
      print ln " " $0
      next
    }
    
    {
      print $0
    }
    

    ...

    awk -f script.awk -v m='' < input.txt
    

提交回复
热议问题