当前位置:网站首页>SED and awk tools of shell
SED and awk tools of shell
2022-04-22 02:20:00 【Skeleton sound】
Such as : stay 2~50 That's ok Add... At the beginning of the line # Note No
:2,50 s/^/#/g
sed
Output all matching character lines
sed -n
"/ character /p" file name
Delete all matching character lines
sed -i
"/ character /d" file name
Replace all matching characters with target characters
sed -i
"s/ character / Target character /g" file name
Replace the matching character of the specified line with the target character
sed -e
'2s/xxxx/yyyy/4' yf.txt
notes : there 2, It means the first one 2 That's ok .
?? there 3, Indicates the second line of each line 3 The second time .
Will match the line beginning with the character , Medium bash Change it to false
ssh $i
"sed -i '/^hmsftp/ s#bash#false#' /etc/passwd"
Add... Before each line “123”
sed -i
"s/^/123/g" file name
Add... At the end of each line “abc”
sed -i
"s/$/abc/g" file name
Add... Below the line of matching characters “abc”
sed -i
"/88888/a\abc" file name
Add... Above the line of matching characters “abc”
sed -i
"/88888/i\abc" file name
Add... Under the third line 888888
sed -i "3a\888888:" /opt/name.txt
=====================

Regular expression applications :grep

grep
"0*" /etc/passwd “0” At least appear 0 Time
grep
"00*" /etc/passwd “0” At least appear 1 Time
grep
"000*" /etc/passwd “0” At least appear 2 Time
grep
[r09] /etc/passwd Anything containing any character in brackets will appear
![[ root@localhost
grep "rooo•" passwd
root : x : root : / root : /bin/bash
operator: x : 11 : e: operator: 'root : / sbin/nologin
[ root@localhost
grep [rø9] /etc/passwd
root : x : root : / root : /bin/bash
adm: x : 3 : 4: adm : /var/adm: /sbin/ nologin
1 p: x : 4: 7 : Ip: /var/ spool/lpd: /sbin/nologin
sync : x : 5 : e: sync : / sbin: /bin/sync
shutdown : x : 6 : e : shutdcwn : /sbin : / sbin/ shutdown
halt: x: 7 halt : /sbin: /sbin/halt [ root@localhost
grep "rooo•" passwd
root : x : root : / root : /bin/bash
operator: x : 11 : e: operator: 'root : / sbin/nologin
[ root@localhost
grep [rø9] /etc/passwd
root : x : root : / root : /bin/bash
adm: x : 3 : 4: adm : /var/adm: /sbin/ nologin
1 p: x : 4: 7 : Ip: /var/ spool/lpd: /sbin/nologin
sync : x : 5 : e: sync : / sbin: /bin/sync
shutdown : x : 6 : e : shutdcwn : /sbin : / sbin/ shutdown
halt: x: 7 halt : /sbin: /sbin/halt](/img/65/7bac89cedaa1ec814fdd3bb8d20399.png)
grep
[^r09] /etc/passwd Anything that does not contain any of the characters in brackets will appear ( Take the opposite )
![root@localhost grep ( Arø9] /etc/passwd
oot : root : 'root : /bin/bash
in: x : 1: 1 : bin: /bin:/sbin/nologin
aerrx)n : x : 2 : 2 : : / sbin : / sbin/ nologin
dm: x : : ach: /var/adm: / sbin/ nologin
p: x : 4: 7 : Ip: /var/spol/lpd : / sbin/ nologin
ync : x: 5 /sbin 'bin/ sync
hutdown : x : 6 : : shutdown : / sbin : / root@localhost grep ( Arø9] /etc/passwd
oot : root : 'root : /bin/bash
in: x : 1: 1 : bin: /bin:/sbin/nologin
aerrx)n : x : 2 : 2 : : / sbin : / sbin/ nologin
dm: x : : ach: /var/adm: / sbin/ nologin
p: x : 4: 7 : Ip: /var/spol/lpd : / sbin/ nologin
ync : x: 5 /sbin 'bin/ sync
hutdown : x : 6 : : shutdown : / sbin : /](/img/9c/bbfa4992da4d542b7e5309c6c4033f.png)
grep
"[0-9]\{2\}" /etc/passwd // Matching inclusion 0-9 Numbers , And a line with two digits , Exactly match .
grep
"[0-9]\{2,\}" /etc/passwd Matching inclusion 0-9 Numbers , Lines with two or more digits
grep
"[0-9]\{1,3\}" /etc/passwd Configuration includes 0-9 Numbers . And there have been 1 Time 2 Time or 3 Every time . Exactly match .
egrep
-v "^$|^#" /etc/vsftpd/vsftpd.conf Put blank lines or # Remove the beginning of the sign .

Egrep
'(xyz)+' passwd


----------- Output related ----------
sed -n
'6p' passwd Put the second... In the file 6 Line output .
sed -n
'6,8p' passwd Put the second... In the file 6 To the first 8 Line output .
sed -n
'6p;8p' passwd Put the second... In the file 6 And the 8 Line output
sed -n
'p;n' passwd Output odd lines in the file
sed -n
'n;p' passwd Output even lines in the file
sed -n
'1,10{n;p}' passwd Put... In the file 1-10 Even rows in rows output
sed -n
'1,10{p;n}' passwd Put... In the file 1-10 Odd rows in rows output
sed -n
'$p' passwd Output the last line of the file .
sed -n
'/root/=' passwd Include... In the file root Line number output of
sed '5q' passwd Before the output file 5 Exit after line information
-------------- Insert correlation ------------
sed '/root/i I AM OK' passwd Include in root Insert content before the line of .
sed '/root/a I AM OK' passwd Include in root Insert content after the line of .
sed
'15a HHHHHHHHH' passwd stay 15 Insert content after line
------- Delete related ------------ Refers to the view , Temporary data deletion , Will not use the original documents
sed
'1d' passwd Delete first line
sed
'4,7d' passwd Delete 4 To 7 That's ok
sed '$d' passwd Delete last line
sed '/^$/d' passwd Delete blank lines
sed
'/root/d' passwd Delete with root The line of
sed
'/^root/d' passwd Delete with root Beginning line
sed
'/root$/d' passwd Delete with root The line at the end
sed
'/nologin$/!d' bb.txt Delete without nologin The line at the end
------- Replace related ------
sed
's/root//g' passwd Put all the root Replace with empty
sed '1,3s/root//g' passwd hold 1-3 Yes root Replace with empty
sed
'/root/c HHHHH' passwd To contain root Replace the line with the specified character
------ If you want to modify the contents of the file, add a i Parameters ----
sed -i
's/enforcing/disabled/' /etc/sysconfig/selinux
-----------AWK relevant - Processing column -------





版权声明
本文为[Skeleton sound]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211407481997.html
边栏推荐
- What are the pitfalls of risk control product quota?
- GreenDao的使用;
- 高级面试题 解析,阿里巴巴发布“限量版”Android零基础宝典
- IP message analysis notes
- Page 107 planning and design of enterprise digital transformation
- error:there‘s no Qt version assigned to project please assign a Qt installation in qt project settin
- 14.系统信息查看
- Window7 activation phone activation notes;
- Redis 缓存数据库使用 Redis-Shake 做数据同步
- Golang 中 select 语句死锁问题
猜你喜欢

Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system

uniapp实现出生日期/时间选择效果

MySQL cannot find my INI file

How to select the appropriate neo4j Version (2022)

Leetcode 141, circular linked list

The advanced UI doesn't understand why they can get a high salary. It's hot

Page 49 information planning and digital transformation of petroleum and petrochemical industry

error:there‘s no Qt version assigned to project please assign a Qt installation in qt project settin

Nacos 为什么这么强

uni-list的插件导入及使用方法
随机推荐
AI应用说-智慧农场(牛场无人监控)
Window7 activation phone activation notes;
DEJA_ Vu3d - cesium feature set 013 - military plotting Series 7: regular polygon
The purpose of software testing, why do you do software testing?
IP message analysis notes
error:there‘s no Qt version assigned to project please assign a Qt installation in qt project settin
Shit, someone poisoned my code comments?
Golang 1.8 generic testing
51 page digital transformation and informatization planning of the 14th five year plan
Leetcode 1572, sum of diagonal elements of matrix
Advanced formula 43 of C language: the meaning of function
当人们越是接近产业互联网,就越来越能真正的看清它
What do you learn about programming
8种MySQL常见SQL错误用法详解
Evaluation of arithmetic four mixed operation expression
Why won't MySQL lose data when the power is suddenly off? (Collection)
【查看已经安装的包和命令是由哪个包提供的】
Plug in import and usage of uni list
NLP模型小总结
102 page master plan for new generation digital transformation and informatization