工作中有用到,做个记录。
1. 查询某字段,显示行号:
cat -n file_name|grep '查找字段'
[root@ZWZF-CWY-LZY-12 CWY]# cat -n nohup.out |grep 'JVM'
10445 2022-12-15 17:54:35.908 cwy-web [,] [main] INFO [StartupInfoLogger.java:61] - Started CwyApplication in 252.596 seconds (JVM running for 266.291)
2. 查询某字段,不显示行号:
grep '查找字段' file_name
[root@ZWZF-CWY-LZY-12 CWY]# grep 'JVM' nohup.out
2022-12-15 17:54:35.908 cwy-web [,] [main] INFO [StartupInfoLogger.java:61] - Started CwyApplication in 252.596 seconds (JVM running for 266.291)
[root@ZWZF-CWY-LZY-12 CWY]#
3. 统计某字段在文件中出现的行数:
grep -o '查找字段' file_name|wc -l
[root@ZWZF-CWY-LZY-12 CWY]# grep -o JVM nohup.out |wc -l 1
手机扫一扫
移动阅读更方便
你可能感兴趣的文章