耀火健身教练培训基地环境
在一个阳光明媚、碧空如洗的中午,一个挠头的要领员正在与团队一姐排查超时问题,只见一姐手速极快的查找着一个又一个日记,快速定位到一个又一个嫌疑东说念主,仰慕之情油联系词生,为了后续也大概在小迷妹手上秀本事,是以暗下决心准备学习这个给力的东西。底下有请今天的主角(grep辅导)闪亮登场。
一、基本语法grep这个linux辅导环球一定不生分,其用于查找文献中合适要求的字符串,底下来望望这个高频的辅导如何使用。
菠菜送彩金平台皇冠现金grep 耀火健身教练培训基地环境[选项] 查找本色 [源文献]
不雅察其构成结构,由四部分构成:辅导名(grep)、选项、查找本色、源文献,其中需要肃肃的有两个位置,底下让咱们逐步说念来。
源文献
源文献部分是无关大局的,若不指定任何文献称号或是所赐与的文献名为-,则grep辅导会从模范输入诞生读取数据,其使用如下所示:
// 文献旅途为/test // 袭取cat的输入 cat ./test |grep 'hello' // 存在旅途部分参数 grep 'hello' ./test
选项部分
虎扑体育app 如何赚钱选项部分比拟多,不错通过grep --help辅导来看一下有哪些选项:
席间,章泽天一袭黑色紧身礼服,鲜眉亮眼,整个人的精神气色看起来都很好,网传三胎谣言不攻自破。
Regexp selection and interpretation: // 正则抒发式遴荐和透露 -E, --extended-regexp PATTERN is an extended regular expression (ERE) -F, --fixed-strings PATTERN is a set of newline-separated 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 display version information and exit --help display this help text and exit 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 file name for each match -h, --no-filename suppress the file name prefix on output --label=LABEL use LABEL as the standard input file name prefix -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, --recursive like --directories=recurse -R, --dereference-recursive likewise, but follow all symlinks --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/Windows) -u, --unix-byte-offsets report offsets as if CRs were not there
看着选项本色简直许多,背起来确凿不易,亏得文档中给咱们作念了分类,只需要记着这些分类是干什么的,然后在需要的时辰从内部进行搜索即可快速搜寻到所需用法(嗅觉看其本色必看菜鸟教程上的本色容易许多)
(1)当需要通过正则的神色进行搜索本色时,去"Regexp selection and interpretation"区块找选项即可,常用的有:
皇冠app-E:通过正则抒发式进行搜索
(2)当需要对输出的本色进行扬弃时,去"Output control"区块找选项即可,常用的有如下几个:
-m 数目:表征匹配若干次就会罢手 -n:裸露匹配行及行号 -H:打印每一个匹配的文献名 -r:大概递归查询,即不错输入文献夹查询 -c:统计匹配到行的个数
(3)当需要得到输出本色的潦倒文进行专揽时,皇冠足球去"Context control"区块找选项即可,常用的有如下几个:
-B 数目、-A 数目、-C 数目:分别表征得到本色前、后、前后几行 --color:对输出的本色添加神采
(4)除了一些分手比拟领略的选项,还有一些选项我个东说念主以为分手的并不是很合理,然而它们仍然很迫切,让咱们一王人来望望有哪些:
-i:忽略字母大小写 -v:反向遴荐,也即是裸透露莫得搜索出字符串本色的那一瞥二、经典用法
上头也曾将其基本使用作念了看重的发达,俗语说的好:光说不练假把式,光练不说真把式,连说带练全把式。既然上头发达了一通表面的东西,底下咱们就来实战几个常用场景,将表面付诸于捏行。在实战之前先创建一个文献,文献名是test,文献本色如下所示:
hello world!!! dog cat pig big pig tiger Elephant
从详情文献中过滤出包含pig的
$ grep 'pig' ./test pig big pig
从包含某一部安分容的文献中过滤包含pig的
$ grep 'pig' ./te* pig big pig
从某一文献夹下整个本色中过滤出包含pig的
www.apexathleticpro.com$ grep -r 'pig' . ./test:pig ./test:big pig
从某一文献中过滤出不包含pig的
$ grep -v 'pig' ./test hello world!!! dog cat tiger Elephant
在过滤文献时裸露行数
188bet金宝博$ grep -n 'pig' ./test 4:pig 5:big pig
匹配出以起原的本色(通过基本正则抒发式匹配即可,基本正则抒发式字符有^$.[]*)
$ grep ^p ./test pig
匹配出包含pig或cat本色的行(用到了彭胀正则抒发式,其在基本正则抒发式基础上加多了(){}?+|等)
皇冠博彩网站博彩游戏种类丰富多样,无论是彩票、真人博彩、电子游戏还是体育赛事,网站满足博彩爱好者不同需求,同时网站提供博彩攻略技巧分享,广大博彩爱好者带来更好博彩体验。$ grep -E 'pig|cat' ./test cat pig big pig
匹配出包含hello和world本色的行
$ grep 'hello' ./test |grep 'world' hello world!!!
得到到匹配本色‘big pig'的前一瞥本色
$ grep -B1 'big pig' ./test pig big pig
得到匹配到'pig'行的数目
$ grep -c 'pig' ./test 2
得到到的pig行的本色高亮裸露
$ grep --color 'pig' ./test pig big pig
经典用法还有许多,不行再逐一进行胪列了,只需要知说念在过滤本色时用此妙技能经管80%的问题,但这就弥散让我方成为最亮的阿谁崽。
2026世界杯球衣挪威·环球好,我是捏鸢者,毕业于华中科技大学,新期间农民工,当今是百度前端研发工程师,著有《前端百题斩》、数十篇学习想维导图(go、React、Redux、Vue、Vuex、操作系统、Linux、策画步地、js、webpack、nginx)以及浩繁前端进阶著作。
本文转载自微信公众号「前端点线面」,不错通过以下二维码温暖。转载本文请联系前端点线面公众号。
皇冠客服飞机:@seo3687

