grep 并列查询 效率 且 或
find / | grep -v python | grep -v xl_ | grep -v xiaole |grep redis
[root@hadoop3 ~]# find / | grep -v {python|xl_|xiaole} |grep redis
-bash: xl_: 未找到命令
-bash: xiaole}: 未找到命令
[root@hadoop3 ~]# find / | grep -vE "python|xl_|xiaole" |grep redis
/home/hadoop/.pycharm_helpers/typeshed/third_party/2/redis
/home/hadoop/.pycharm_helpers/typeshed/third_party/2/redis/client.pyi
/home/hadoop/.pycharm_helpers/typeshed/third_party/2/redis/connection.pyi
/home/hadoop/.pycharm_helpers/typeshed/third_party/2/redis/exceptions.pyi
/home/hadoop/.pycharm_helpers/typeshed/third_party/2/redis/utils.pyi
/home/hadoop/.pycharm_helpers/typeshed/third_party/2/redis/__init__.pyi
/run/redis_6379.pid
/etc/systemd/system/redis-sentinel.service.d
/etc/systemd/system/redis-sentinel.service.d/limit.conf
/etc/systemd/system/redis.service.d
/etc/systemd/system/redis.service.d/limit.conf
/etc/selinux/targeted/modules/active/modules/redis.pp
/etc/logrotate.d/redis
/etc/redis-sentinel.conf
/etc/redis.conf
/root/.rediscli_history
/root/.pycharm_helpers/typeshed/third_party/2/redis
/root/.pycharm_helpers/typeshed/third_party/2/redis/client.pyi
/root/.pycharm_helpers/typeshed/third_party/2/redis/connection.pyi
/root/.pycharm_helpers/typeshed/third_party/2/redis/exceptions.pyi
/root/.pycharm_helpers/typeshed/third_party/2/redis/utils.pyi
/root/.pycharm_helpers/typeshed/third_party/2/redis/__init__.pyi
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/from_repo
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/reason
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/releasever
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/var_uuid
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/var_infra
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/command_line
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/checksum_type
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/checksum_data
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/origin_url
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/from_repo_revision
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/from_repo_timestamp
/var/lib/yum/yumdb/r/08da4c69e0806230238dc7d3a187fe5b27c1a20b-redis-3.2.10-2.el7-x86_64/installed_by
/var/lib/redis
/var/lib/redis/dump.rdb
/var/log/redis
/var/log/redis/redis.log
/var/log/redis/redis.log-20180107
/usr/bin/redis-benchmark
/usr/bin/redis-check-aof
/usr/bin/redis-check-rdb
/usr/bin/redis-cli
/usr/bin/redis-sentinel
/usr/bin/redis-server
/usr/lib/systemd/system/redis-sentinel.service
/usr/lib/systemd/system/redis.service
/usr/share/doc/redis-3.2.10
/usr/share/doc/redis-3.2.10/00-RELEASENOTES
/usr/share/doc/redis-3.2.10/BUGS
/usr/share/doc/redis-3.2.10/CONTRIBUTING
/usr/share/doc/redis-3.2.10/MANIFESTO
/usr/share/doc/redis-3.2.10/README.md
/usr/share/man/man1/redis-benchmark.1.gz
/usr/share/man/man1/redis-check-aof.1.gz
/usr/share/man/man1/redis-check-rdb.1.gz
/usr/share/man/man1/redis-cli.1.gz
/usr/share/man/man1/redis-sentinel.1.gz
/usr/share/man/man1/redis-server.1.gz
/usr/share/man/man5/redis.conf.5.gz
/usr/share/man/man5/redis-sentinel.conf.5.gz
/usr/share/licenses/redis-3.2.10
/usr/share/licenses/redis-3.2.10/COPYING
/usr/share/nmap/nselib/redis.lua
/usr/share/nmap/scripts/redis-brute.nse
/usr/share/nmap/scripts/redis-info.nse
/usr/libexec/redis-shutdown
[root@hadoop3 ~]#
[root@hadoop3 redis]# find / | grep -E "redis*rdb"
[root@hadoop3 redis]# find / | grep -E "redis.*rdb"
/var/lib/redis/dump.rdb
/var/lib/redis/temp-11688.rdb
/usr/bin/redis-check-rdb
/usr/share/man/man1/redis-check-rdb.1.gz
[root@hadoop3 redis]# find / | grep -E redis.*rdb
/var/lib/redis/dump.rdb
/var/lib/redis/temp-11688.rdb
/usr/bin/redis-check-rdb
/usr/share/man/man1/redis-check-rdb.1.gz
[root@hadoop3 redis]# find / | grep -vE python|xl_|xiaole |grep redis
-bash: xl_: 未找到命令
-bash: xiaole: 未找到命令
[root@hadoop3 redis]#
grep 排除 包含
ps -aux | grep -E *www* 包含www
ps -aux | grep -vE *www* 不包含www
egrep执行效果与"grep-E"
Linux egrep命令用于在文件内查找指定的字符串。
egrep执行效果与"grep-E"相似,使用的语法及参数可参照grep指令,与grep的不同点在于解读字符串的方法。
egrep是用extended regular expression语法来解读的,而grep则用basic regular expression 语法解读,extended regular expression比basic regular expression的表达更规范。
给定一个包含电话号码列表(一行一个电话号码)的文本文件 file.txt
,写一个 bash 脚本输出所有有效的电话号码。
你可以假设一个有效的电话号码必须满足以下两种格式: (xxx) xxx-xxxx 或 xxx-xxx-xxxx。(x 表示一个数字)
你也可以假设每行前后没有多余的空格字符。
示例:
假设 file.txt
内容如下:
987-123-4567 123 456 7890 (123) 456-7890
你的脚本应当输出下列有效的电话号码:
987-123-4567 (123) 456-7890
egrep '^[0-9]{3}-[0-9]{3}-[0-9]{4}$|^\([0-9]{3}\) [0-9]{3}-[0-9]{4}$' file.txt 注意或 、空格
查找C语言strlen源码所在文件
find / | grep string.h | grep -v xiaole | xargs grep strlen