grep/pgrep/egrep/fgrep
Differences between grep, pgrep, egrep, and fgrep (Linux):
grep
grep is an acronym that stands for "Global Regular Expressions Print". grep is a program which scans a specified file or files line by line, returning lines that contain a pattern. A pattern is an expression that specifies a set of strings by interpreting characters as meta-characters. For example the asterisk meta character (*) is interpreted as meaning "zero or more of the preceding element". This enables users to type a short series of characters and meta characters into a grep command to have the computer show us what lines in which files match.
The standard grep command looks like:
grep <flags> '<regular expression>' <filename>
grep prints the search results to the screen (stdout) and returns the following exit values:
0 A match was found.
1 No match was found.
>1 A syntax error was found or a file was inaccessible
(even if matches were found).
Some common flags are: -c
for counting the number of successful matches and not printing the actual matches, -i
to make the search case insensitive, -n
to print the line number before each match printout, -v
to take the complement of the regular expression (i.e. return the lines which don't match), and -l
to print the file names of files with lines which match the expression.
egrep
egrep is an acronym that stands for "Extended Global Regular Expressions Print".
The 'E' in egrep means treat the pattern as a regular expression. "Extended Regular Expressions" abbreviated 'ERE' is enabled in egrep. egrep (which is the same as grep -E
) treats +
, ?
, |
, (
, and )
as meta-characters.
In basic regular expressions (with grep), the meta-characters ?
, +
, {
, |
, (
, and )
lose their special meaning. If you want grep to treat these characters as meta-characters, escape them \?
, \+
, \{
, \|
, \(
, and \)
.
For example, here grep uses basic regular expressions where the plus is treated literally, any line with a plus in it is returned.
grep "+" myfile.txt
egrep on the other hand treats the "+" as a meta character and returns every line because plus is interpreted as "one or more times".
egrep "+" myfile.txt
Here every line is returned because the +
was treated by egrep as a meta character. normal grep would have searched only for lines with a literal +
.
fgrep
fgrep is an acronym that stands for "Fixed-string Global Regular Expressions Print".
fgrep (which is the same as grep -F) is fixed or fast grep and behaves as grep but does NOT recognize any regular expression meta-characters as being special. The search will complete faster because it only processes a simple string rather than a complex pattern.
For example, if I wanted to search my .bash_profile for a literal dot (.) then using grep would be difficult because I would have to escape the dot because dot is a meta character that means 'wild-card, any single character':
grep "." myfile.txt
The above command returns every line of myfile.txt. Do this instead:
fgrep "." myfile.txt
Then only the lines that have a literal '.' in them are returned. fgrep helps us not bother escaping our meta characters.
pgrep
pgrep is an acronym that stands for "Process-ID Global Regular Expressions Print".
pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout. pgrep is handy when all you want to know is the process id integer of a process. For example, if I wanted to know only the process ID of my mysql process I would use the command pgrep mysql
which would return a process ID like 7312.
来自:http://superuser.com/questions/508881/what-is-the-difference-between-grep-pgrep-egrep-fgrep
grep/pgrep/egrep/fgrep的更多相关文章
- grep, egrep, fgrep笔记
grep, egrep, fgrep grep: 根据模式搜索文本,并将符合模式的文本行显示出来.Pattern: 文本字符和正则表达式的元字符组合而成匹配条件 grep [options] PATT ...
- grep egrep fgrep命令
一.grep.egrep.fgrep命令 本文中主要介绍了linux系统下grep egrep fgrep命令和正则表达式的基本参数和使用格式.方法.(注释:文中fg代表例子,) 1.1.基本定义: ...
- grep与正则表达式,grep、egrep和fgrep
grep用法详解:grep与正则表达式 首先要记住的是: 正则表达式与通配符不一样,它们表示的含义并不相同!正则表达式只是一种表示法,只要工具支持这种表示法, 那么该工具就可以处理正则表达式的字符串. ...
- grep、egrep、fgrep的用法与特性详解
[转载自]http://tanxw.blog.51cto.com/4309543/1361993 开篇 学习Linux也有一段时间了,对Linux多少也算是有点了解了,越是了解也就越对这 ...
- Linux三剑客之grep 与 egrep
grep: Linux上文本处理三剑客 grep:文本过滤(模式:pattern)工具; *(grep, egrep, fgrep) sed:stream editor,文本编辑工具: awk:Lin ...
- linux中grep和egrep的用法
1. grep简介 grep (global search regular expression_r(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大 ...
- Linux正则表达式grep与egrep
grep -io "http:/=[A-Z0-9]\{16\}" ./wsxf.txt >wsxf_urls.txt Linux正则表达式grep与egrep 正则表达式:它 ...
- grep和egrep正则表达式
Linux上文本处理三剑客 grep :文本过滤( 模式:pattern) 工具 grep, egrep, fgrep (不支持正则表达式搜索,但搜索纯文本的数据最快) sed :stream edi ...
- grep、egrep命令用法
何谓正则表达式 正则表达式,又称正规表示法.常规表示法(Regular Expression,在代码中常简写为regex.regexp或RE),是一类字符所书写的模式,其中许多字符不表示其字面意义,而 ...
随机推荐
- android 知识点汇总
1.activity 它是 android 应用程序的基本功能单元.一个Activity是一个应用程序组件,提供一个屏幕,用户可以用来交互为了完成某项任务,例如拨号.拍照.Activity 本身是没有 ...
- vue-router两种模式,到底什么情况下用hash,什么情况下用history模式呢?
转:https://segmentfault.com/q/1010000010340823/a-1020000010598395 为什么要有 hash 和 history 对于 Vue 这类渐进式前端 ...
- jquery幻灯片插件之owl.carousel.js
官网地址:http://owlcarousel2.github.io/OwlCarousel2/ 这个插件兼容各种浏览器,以及移动端 使用方法: 1.下载文件,解压以后,把dist里面的文件放到项目中 ...
- JavaScript 使用 mediaDevices API 选择摄像头
大多数智能手机都有前置和后置摄像头,当你在创建视频应用时你可能想要选择或者切换前置.后置摄像头. 如果你开发的是一款聊天应用,你很可能会想调用前置摄像头,但如果你开发的是一款拍照软件,那么你会更倾向于 ...
- 性能测试六:jmeter进阶之Cookie与header管理器
一.http cookie管理器 可以在浏览器中抓取到cookie信息,然后通过http cookie管理器为http请求添加cookie信息 添加cookie管理器后,Jmeter可以自动处理coo ...
- 《转》MySQL 5.7版本新特性连载
MySQL 5.7版本新特性连载(一) 本文将和大家一起分享下5.7的新特性,不过我们要先从即将被删除的特性以及建议不再使用的特性说起.根据这些情况,我们在新版本及以后的版本中,应该不再使用,避免未来 ...
- python 全栈开发,Day122(人工智能初识,百度AI)
一.人工智能初识 什么是智能? 我们通常把人成为智慧生物,那么”智慧生物的能力”就是所谓的”智能”我们有什么能力?听,说,看,理解,思考,情感等等 什么是人工智能? 顾名思义就是由人创造的”智慧能力” ...
- 事件方法on()
on()方法用来处理事件.jQuery会处理所有浏览器的兼容性问题. on()方法可以指定影响哪个事件,相当于JavaScript中的addEventListener()事件监听. on()方法有两个 ...
- HDU1850 尼姆博弈求可行方案数目
尼姆博弈(Nimm's Game) 题型 尼姆博弈模型,大致上是这样的: 有3堆各若干个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取1个,多者不限,最后取光者得胜. 分析 1.首先自己想一下 ...
- Springboot实现filter拦截token验证和跨域
背景 web验证授权合法的一般分为下面几种 使用session作为验证合法用户访问的验证方式 使用自己实现的token 使用OCA标准 在使用API接口授权验证时,token是自定义的方式实现起来不需 ...