欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获取指定字符串的行号

程序员文章站 2022-07-14 19:27:34
...

获取指定字符串的行号


file.txt:
------------------------------------------------------[BOARD_CFG]
PLATFORM = hisiv500
SERIAL = LEDxxX8800B
BOARD = LED43X8800B
MODEL = KONKA_TV
CODE = 99016870
BUILD_MODE = RELEASE
AN_VERSION = V2.3.06
AN_BUILD = 2476
DATE = 09:48:33 2016-11-08

[PNL_CFG]
PNL_NAME = PNL_72000915YT_LG43_LC430DUY-SHA2
PNL_NUM = 72000915YT
PNL_CODE = 99015414
PNL_BUILD = 2476
PNL_VERSION = V2.3.00

1、grep -nr AN_VERSION  file.txt  | awk -F: '{print $2}'
2、cat file.txt | awk '/AN_VERSION/ {print NR}'