grep 命令过滤配置文件中的注释和空行
2023-03-07 09:42:03 时间
grep 用法
Usage: grep [OPTION]... PATTERN [FILE]... Search for PATTERN in each FILE or standard input. PATTERN is, by default, a basic regular expression (BRE). Example: grep -i 'hello world' menu.h main.c Regexp selection and interpretation: -E, --extended-regexp PATTERN is an extended regular expression (ERE) -F, --fixed-strings PATTERN is a set of newline-separated fixed strings -G, --basic-regexp PATTERN is a basic regular expression (BRE) -P, --perl-regexp PATTERN is a Perl regular expression -e, --regexp=PATTERN use PATTERN for matching -f, --file=FILE obtain PATTERN from FILE -i, --ignore-case ignore case distinctions -w, --word-regexp force PATTERN to match only whole words -x, --line-regexp force PATTERN to match only whole lines -z, --null-data a data line ends in 0 byte, not newline Miscellaneous: -s, --no-messages suppress error messages -v, --invert-match select non-matching lines -V, --version print version information and exit --help display this help and exit --mmap ignored for backwards compatibility Output control: -m, --max-count=NUM stop after NUM matches -b, --byte-offset print the byte offset with output lines -n, --line-number print line number with output lines --line-buffered flush output on every line -H, --with-filename print the filename for each match -h, --no-filename suppress the prefixing filename on output --label=LABEL print LABEL as filename for standard input -o, --only-matching show only the part of a line matching PATTERN -q, --quiet, --silent suppress all normal output --binary-files=TYPE assume that binary files are TYPE; TYPE is `binary', `text', or `without-match' -a, --text equivalent to --binary-files=text -I equivalent to --binary-files=without-match -d, --directories=ACTION how to handle directories; ACTION is `read', `recurse', or `skip' -D, --devices=ACTION how to handle devices, FIFOs and sockets; ACTION is `read' or `skip' -R, -r, --recursive equivalent to --directories=recurse --include=FILE_PATTERN search only files that match FILE_PATTERN --exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN --exclude-from=FILE skip files matching any file pattern from FILE --exclude-dir=PATTERN directories that match PATTERN will be skipped. -L, --files-without-match print only names of FILEs containing no match -l, --files-with-matches print only names of FILEs containing matches -c, --count print only a count of matching lines per FILE -T, --initial-tab make tabs line up (if needed) -Z, --null print 0 byte after FILE name Context control: -B, --before-context=NUM print NUM lines of leading context -A, --after-context=NUM print NUM lines of trailing context -C, --context=NUM print NUM lines of output context -NUM same as --context=NUM --color[=WHEN], --colour[=WHEN] use markers to highlight the matching strings; WHEN is `always', `never', or `auto' -U, --binary do not strip CR characters at EOL (MSDOS) -u, --unix-byte-offsets report offsets as if CRs were not there (MSDOS)
例子
# 显示过滤注释( # ; 开头) 和空行后的配置信息 $ grep -Ev "^$|^[#;]" server.conf
# 显示所有带 root 的行 $ grep root /etc/passwd root:x:0:0:root:/root:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin $ cat /etc/passwd | grep root root:x:0:0:root:/root:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin
# 将没有出现 root 的行取出来 $ grep -v root /etc/passwd
相关文章
- 什么是极速文件传输,极速文件传输如何进行大文件传输
- 【低代码】1570- 9个顶级无代码开发工具
- 迈迪克,一家专注生命科学领域自动化的平台型企业
- 北理工团队创建面向多任务操控的脑机协同控制方法并应用于智能车辆
- EasyDSS私有化部署:如何有效整合服务器带宽与性能资源实现高并发?
- 终于有人把AB实验讲明白了
- 聊聊这个SaaS领域爆火的话题
- 终于有人把分布式机器学习讲明白了
- 为什么我不建议自研BI系统?
- CMU研究人员开创CMU阵列,3D打印且完全可定制的脑机接口微电极阵列
- 揭秘短视频推荐系统的技术架构及四大模块
- 什么是一网统管?终于有人讲明白了
- [oeasy]python0082_VT100_演化_颜色设置_VT选项_基础色_高亮色_索引色_RGB总结
- 设备管理系统——企业设备管理的利器
- 数据、算法、场景:工程化的“三驾马车”
- 什么是AB实验?能解决什么问题?终于有人讲明白了
- Roblox、Epic Games和Meta,详解三巨头如何引爆元宇宙
- 终于有人把HDFS架构和读写流程讲明白了
- 为什么很多城市都在搞“一网统管”?有什么用?
- 如何利用ChatGPT学英语?