当前位置:网站首页>Grep tool
Grep tool
2022-06-29 22:28:00 【51CTO】
Course objectives of this section
● understand shell Wildcard in
● be familiar with grep、cut、sort And other gadgets shell Wildcard in Use
One 、 Text processing tools
1. grep Tools
grep yes ** That's ok ** Filter tool ; Used to filter lines according to keywords
Grammar and options
grammar
Common options :
OPTIONS:
-i: Case insensitive
-v: Find lines that do not contain the specified content , Reverse selection
-w: Search by word
-o: Print matching keywords
-c: Count the number of rows matched
-n: According to the line Numbers
-r: Traverse the directory layer by layer to find
-A: Show matching lines and how many lines follow
-B: Show matching lines and how many lines ahead
-C: Show how many lines before and after the match line
-l: Only matching file names are listed
-L: List mismatched filenames
-e: Use regular matching
-E: Use extended regular matching
^key: Start with a keyword
key$: End with keywords
^$: Match blank line
--color=auto : You can add color to the key words you find
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
Color display ( The alias set ):
Temporary settings :
# alias grep='grep --color=auto' // Only valid for current terminal and current user
Permanent settings :
1) overall situation ( Effective for all users )
vim /etc/bashrc
alias grep='grep --color=auto'
source /etc/bashrc
2) Local ( For a specific user )
vim ~/.bashrc
alias grep='grep --color=auto'
source ~/.bashrc
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
Illustrate with examples :
explain : Don't use... Directly /etc/passwd file , Copy it to /tmp Next experiment !
# grep -i root passwd Ignore case matching to include root The line of
# grep -w ftp passwd Exactly match ftp word
# grep -w hello passwd Exactly match hello word ; Add your own include hello Line to file
# grep -wo ftp passwd Print matching keywords ftp
# grep -n root passwd Print match to root Good keyword
# grep -ni root passwd Ignore case matching statistics including keywords root The line of
# grep -nic root passwd Ignore case matching statistics including keywords root The number of rows
# grep -i ^root passwd Ignore case matching to root Beginning line
# grep bash$ passwd Match with bash The line at the end
# grep -n ^$ passwd Match blank lines and print line numbers
# grep ^# /etc/vsftpd/vsftpd.conf Match with # The line at the beginning of the number
# grep -v ^# /etc/vsftpd/vsftpd.conf Match not to # The line at the beginning of the number
# grep -A 5 mail passwd Matching inclusion mail Keywords and after 5 That's ok
# grep -B 5 mail passwd Matching inclusion mail Keywords and before 5 That's ok
# grep -C 5 mail passwd Matching inclusion mail Keywords and before and after 5 That's ok
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
2. cut Tools
cut yes ** Column ** Interception tools , For column truncation
Grammar and options
grammar :
Common options :
Illustrate with examples :
# cut -d: -f1 1.txt With : Colon division , Cut off the 1 Column content
# cut -d: -f1,6,7 1.txt With : Colon division , Cut off the 1,6,7 Column content
# cut -c4 1.txt Intercept every line in the file 4 Characters
# cut -c1-4 1.txt Intercept each line of the file 1-4 Characters
# cut -c4-10 1.txt Intercept each line of the file 4-10 Characters
# cut -c5- 1.txt From 5 Characters begin to intercept all the following characters
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
Class practice : Use a gadget to list the operating levels of your current system .5/3
- How to view the system operation level
- command
runlevel
- file
/etc/inittab
- How to filter run levels
runlevel |cut -c3
runlevel | cut -d ' ' -f2
grep -v '^#' /etc/inittab | cut -d: -f2
grep '^id' /etc/inittab |cut -d: -f2
grep "initdefault:$" /etc/inittab | cut -c4
grep -v ^# /etc/inittab |cut -c4
grep 'id:' /etc/inittab |cut -d: -f2
cut -d':' -f2 /etc/inittab |grep -v ^#
cut -c4 /etc/inittab |tail -1
cut -d: -f2 /etc/inittab |tail -1
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
边栏推荐
- Can you be a coder if you don't learn English well? Stop worrying and learn it first
- leetcode:91. 解码方法【dfs + 记忆化】
- 新手必须知道的 Kubernetes 架构
- Data mining review
- MySQL,MVCC详解,快照读在RC、RR下的区别
- Optional类的高级使用
- MySQL backup and restore
- 26 years old, 0 basic career change software test, from 3K to 16K monthly salary, a super complete learning guide compiled by me
- 解题元宇宙,网络游戏中的多元通信方案
- LeetCode85+105+114+124
猜你喜欢
ASP dynamically creates table table
联通入库|需要各地联通公司销售其产品的都需要先入总库
Huawei's software testing director with 7 years' experience, several suggestions for all students who want to switch to software testing
科大讯飞 AI 学习机暑期新品发布会 AI + 教育深度结合再创产品新高度
AI场景存储优化:云知声超算平台基于 JuiceFS 的存储实践
一键式文件共享软件Jirafeau
Mysql入库不了表情符号怎么办
Simple analysis of wieshark packet capturing MySQL protocol
The inadvertently discovered [tidb cache table] can solve the read / write hotspot problem
解题元宇宙,网络游戏中的多元通信方案
随机推荐
Dynamics 365online lookup lookup field multiple selection
math_基本初等函数图型(幂函数/指数/对数/三角/反三角)
请教一下,CDC2.2.1可以同时监听多个pgsql 的库吗?
稳!上千微服务接入 Zadig 的最佳姿势(Helm Chart 篇)
AI场景存储优化:云知声超算平台基于 JuiceFS 的存储实践
Portable 4K audio and video conference terminal all-in-one machine with 8x digital zoom
免费将pdf转换成word的软件分享,这几个软件一定要知道!
一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】
MySQL lock common knowledge points & summary of interview questions
26岁,0基础转行软件测试,从月薪3k到16k,我整理的超全学习指南
Vs2013 how to make the program run on other computers
这次跟大家聊聊技术,也聊聊人生
MySQL backup and restore
5-1 system vulnerability scanning
Deep learning remote sensing data set
static关键字续、继承、重写、多态
Live broadcast platform development, enter the visual area to execute animation, dynamic effects and add style class names
关于深度学习的概念理解(笔记)
联通入库|需要各地联通公司销售其产品的都需要先入总库
Guangzhou launched a campaign to promote the safety of bottled gas and popularized the knowledge of gas safety