发布日期:2023-1-8 更新日期: 2023-1-10文章字数 0阅读时长:0分钟

type
Post
status
Published
date
Jan 8, 2023
slug
linux-sjk-2
summary
tags
linux
学习笔记
category
学习思考
icon
password
Property
Jan 10, 2023 07:13 AM
URL

1. 语法

grep 参数 匹配模式 文件

1.1 参数

参数
作用
-i
忽略大小写
-o
仅显示匹配到的字符
-v
显示不能被匹配的行
-E
使用扩展的语法
-q
静默模式,不输出
-n
显示行号
-c
匹配结果的行数
 

1.2 模式

模式
作用

2. 实战

找出 /etc/passwd 文件中的有 root 的行 ,并且显示在文件中的行号,忽略大小写
grep -in "root" /etc/passwd
notion image
可以看到这里帮你标红了,alias 可以看到,默认使用了颜色
notion image
加上参数 -c 还能看到匹配了几行
notion image
找出所有的非空行
首先使用 ^$ 可以匹配所有空行
grep '^$' file
加上参数 -v 做反转,这样就能找到所有的非空行,再加上 -n 就能显示行数字
grep -vn '^$' file
notion image
 
 

Mathematica 编程实战(4) Mathematica 编程实战(4)