8000 修改 grep 命令代码高亮样式。 #80 · GreateCode/linux-command@829fdd6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 829fdd6

Browse files
committed
修改 grep 命令代码高亮样式。 jaywcjlove#80
1 parent 6ded097 commit 829fdd6

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

command/grep.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ grep
99

1010
### 选项
1111

12-
```bash
12+
```shell
1313
-a --text # 不要忽略二进制数据。
1414
-A <显示行数> --after-context=<显示行数> # 除了显示符合范本样式的那一行之外,并显示该行之后的内容。
1515
-b --byte-offset # 在显示符合范本样式的那一行之外,并显示该行之前的内容。
@@ -42,7 +42,7 @@ grep
4242

4343
### 规则表达式
4444

45-
```bash
45+
```shell
4646
^ # 锚定行的开始 如:'^grep'匹配所有以grep开头的行。
4747
$ # 锚定行的结束 如:'grep$' 匹配所有以grep结尾的行。
4848
. # 匹配一个非换行符的字符 如:'gr.p'匹配gr后接一个任意字符,然后是p。
@@ -65,40 +65,40 @@ x\{m,n\} # 重复字符x,至少m次,不多于n次,如:'o\{5,10\}'匹配
6565

6666
在文件中搜索一个单词,命令会返回一个包含 **“match_pattern”** 的文本行:
6767

68-
```bash
68+
```shell
6969
grep match_pattern file_name
7070
grep "match_pattern" file_name
7171
```
7272

7373
在多个文件中查找:
7474

75-
```bash
75+
```shell
7676
grep "match_pattern" file_1 file_2 file_3 ...
7777
```
7878

7979
输出除之外的所有行 **-v** 选项:
8080

81-
```bash
81+
```shell
8282
grep -v "match_pattern" file_name
8383
```
8484

8585
标记匹配颜色 **--color=auto** 选项:
8686

87-
```bash
87+
```shell
8888
grep "match_pattern" file_name --color=auto
8989
```
9090

9191
使用正则表达式 **-E** 选项:
9292

93-
```bash
93+
```shell
9494
grep -E "[1-9]+"
9595
#
9696
egrep "[1-9]+"
9797
```
9898

9999
只输出文件中匹配到的部分 **-o** 选项:
100100

101-
```bash
101+
```shell
102102
echo this is a test line. | grep -o -E "[a-z]+\."
103103
line.
104104

@@ -108,13 +108,13 @@ line.
108108

109109
统计文件或者文本中包含匹配字符串的行数 **-c** 选项:
110110

111-
```bash
111+
```shell
112112
grep -c "text" file_name
113113
```
114114

115115
输出包含匹配字符串的行数 **-n** 选项:
116116

117-
```bash
117+
```shell
118118
grep "text" -n file_name
119119
#
120120
cat file_name | grep "text" -n
@@ -125,37 +125,37 @@ grep "text" -n file_1 file_2
125125

126126
打印样式匹配所位于的字符或字节偏移:
127127

128-
```bash
128+
```shell
129129
echo gun is not unix | grep -b -o "not"
130130
7:not
131131
#一行中字符串的字符便宜是从该行的第一个字符开始计算,起始值为0。选项 **-b -o** 一般总是配合使用。
132132
```
133133

134134
搜索多个文件并查找匹配文本在哪些文件中:
135135

136-
```bash
136+
```shell
137137
grep -l "text" file1 file2 file3...
138138
```
139< 8000 /td>139

140140
### grep递归搜索文件
141141

142142
在多级目录中对文本进行递归搜索:
143143

144-
```bash
144+
```shell
145145
grep "text" . -r -n
146146
# .表示当前目录。
147147
```
148148

149149
忽略匹配样式中的字符大小写:
150150

151-
```bash
151+
```shell
152152
echo "hello world" | grep -i "HELLO"
153153
# hello
154154
```
155155

156156
选项 **-e** 制动多个匹配样式:
157157

158-
```bash
158+
```shell
159159
echo this is a text line | grep -e "is" -e "line" -o
160160
is
161161
line
@@ -170,7 +170,7 @@ echo aaa bbb ccc ddd eee | grep -f patfile -o
170170

171171
在grep搜索结果中包括或者排除指定文件:
172172

173-
```bash
173+
```shell
174174
# 只在目录中所有的.php和.html文件中递归搜索字符"main()"
175175
grep "main()" . -r --include *.{php,html}
176176

@@ -184,7 +184,7 @@ grep "main()" . -r --exclude-from filelist
184184

185185
使用0值字节后缀的grep与xargs:
186186

187-
```bash
187+
```shell
188188
# 测试文件:
189189
echo "aaa" > file1
190190
echo "bbb" > file2
@@ -197,14 +197,14 @@ grep "aaa" file* -lZ | xargs -0 rm
197197

198198
grep静默输出:
199199

200-
```bash
200+
```shell
201201
grep -q "test" filename
202202
# 不会输出任何信息,如果命令运行成功返回0,失败则返回非0值。一般用于条件测试。
203203
```
204204

205205
打印出匹配文本之前或者之后的行:
206206

207-
```bash
207+
```shell
208208
# 显示匹配某个结果之后的3行,使用 -A 选项:
209209
seq 10 | grep "5" -A 3
210210
5

0 commit comments

Comments
 (0)
0