当前位置:网站首页>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.
边栏推荐
- Hidden worries behind the listing of shushulang: the performance has declined significantly, the market position is relatively backward, and the competitiveness is questionable
- 联通入库|需要各地联通公司销售其产品的都需要先入总库
- LeetCode85+105+114+124
- Daily mathematics serial 54: February 23
- Optional类的高级使用
- static关键字续、继承、重写、多态
- MooseFS基本概念总结
- 解题元宇宙,网络游戏中的多元通信方案
- LeetCode85+105+114+124
- A mysql IBD file is too large processing record
猜你喜欢

合宙AIR32F103CBT6开发板上手报告

一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】

Detailed explanation of MySQL and mvcc and the difference between RC and RR for snapshot reading

MySQL backup and restore

中国数据库崛起,阿里云李飞飞:中国云数据库多种主流技术创新已领先国外

细说GaussDB(DWS)复杂多样的资源负载管理手段

Mysql入库不了表情符号怎么办

从零实现深度学习框架——RNN从理论到实战【实战】

5-1系统漏洞扫描

便携式4K音视频会议终端一体机带8倍数字变焦
随机推荐
细说GaussDB(DWS)复杂多样的资源负载管理手段
The MySQL data cannot be read after the checkpoint recovery. Do you know the reason
jfinal中如何使用过滤器监控Druid监听SQL执行?
稳!上千微服务接入 Zadig 的最佳姿势(Helm Chart 篇)
软件快速交付真的需要以安全为代价吗?
数论-整除分块
Optional类的高级使用
工业细节都是钱和时间砸出来的
ASP using panel to realize simple registration page
动态规划学习(持续更新)
cout 不明确问题
Portable 4K audio and video conference terminal all-in-one machine with 8x digital zoom
leetcode:91. 解码方法【dfs + 记忆化】
[multithreading] how to implement timer by yourself
直播平台开发,进入可视区域执行动画、动效、添加样式类名
正如以往我们对于互联网的看法一样,我们对于互联网的认识开始变得深度
一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】
Daily mathematics serial 54: February 23
【Proteus仿真】步进电机转速数码管显示
[php8+oracle11g+windows environment without tools] Intranet / no network /win10/php connecting to Oracle database instance