Linux-Shell正则表达式(Day1)
本文最后更新于 1333 天前,其中的信息可能已经有所发展或是发生改变。

[TOC]

正则表达式

分类
基础正则 ^ $ ^$ . * [a-z] [^abc]
扩展正则 + |() {} ?

正则和通配符

分类
正则 高级语言、过滤字符、配合sed、grep、awk使用
通配符(glob) 匹配文件名、匹配文件

基础正则

Teach Linux
Like playing basketball and learning

My blog is: https://www.2331314.xyz/
My github is: https://github.com/limitrinno

My qq is 1250644268
My WeChat is weixinhaomajiade

A string of meaningless numbers 0998563245
Good idea, let's start learning now
基础正则
^

^ 以.....开头的行

  • ^github 以github开头的行
  • ^My 以My开头的行

image-20211124162510838

$ 以……结尾的行

  • cat -A 可以看到隐藏的行

image-20211124163229296

  • z $ 可以看到以z结尾的行

image-20211124163351065

…^$ 匹配空行

  • 匹配内容为空的行数
  • 空格也算是一个字符

匹配所有的空格

[root@localhost 2]# grep ' ' clc.txt

Teach Linux
Like playing basketball and learning
My blog is: https://www.2331314.xyz 
My docs is: https://docs.2331314.xyz 
My github is: https://github.com/limitrinno
My qq is 1250644268
My WeChat is weixinhaomajiade
A string of meaningless numbers 0998563245
Good idea, let's start learning now

匹配所有的空行 -n是为了显示行数

[root@localhost 2]# grep '^$' -n clc.txt 
3:
7:
10:

^ $实例

  • 排除文中的空行 (grep -v '^$' clc.txt)
[root@localhost 2]# grep -v '^$' clc.txt 
Teach Linux
Like playing basketball and learning
My blog is: https://www.2331314.xyz 
My docs is: https://docs.2331314.xyz 
My github is: https://github.com/limitrinno
My qq is 1250644268
My WeChat is weixinhaomajiade
A string of meaningless numbers 0998563245
Good idea, let's start learning now
  • 排除文中#开头的行

[root@localhost 2]# cat a.txt

Teach Linux
Like playing basketball and learning

My blog is: https://www.2331314.xyz 
My docs is: https://docs.2331314.xyz 
My github is: https://github.com/limitrinno
#My github is: https://github.com/limitrinno

My qq is 1250644268
My WeChat is weixinhaomajiade
#My WeChat is weixinhaomajiade

A string of meaningless numbers 0998563245
Good idea, let's start learning now

[root@localhost 2]# grep -v '^#' a.txt

Teach Linux
Like playing basketball and learning

My blog is: https://www.2331314.xyz 
My docs is: https://docs.2331314.xyz 
My github is: https://github.com/limitrinno

My qq is 1250644268
My WeChat is weixinhaomajiade

A string of meaningless numbers 0998563245
Good idea, let's start learning now
对此文章 《Linux-Shell正则表达式(Day1)》 如有异议、侵犯您的版权,及时联系我处理或者在本站留言。谢谢!
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇