Use grep to report back only line numbers

前端 未结 8 1449
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 13:40

I have a file that possibly contains bad formatting (in this case, the occurrence of the pattern \\\\backslash). I would like to use grep to return

相关标签:
8条回答
  • 2020-12-04 14:42

    You're going to want the second field after the colon, not the first.

    grep -n "text to find" file.txt | cut -f2 -d:

    0 讨论(0)
  • 2020-12-04 14:43

    Bash version

        lineno=$(grep -n "pattern" filename)
        lineno=${lineno%%:*}
    
    0 讨论(0)
提交回复
热议问题