
运维服务
docker离线安装
一、准备工作:确认架构并下载安装包 1.1 确认目标服务器架构 在目标服务器上执行以下命令,确认系统架构: 输出 x8664:对应 amd64 架构(Intel/AMD 64位服务
[root@www.wulaoer.org wulaoer]# sed -i '1d' access.log [root@www.wulaoer.org wulaoer]# sed -n '1p' access.log 10.10.2.1 2020:02:14:18:1 200 http://www.wulaoer.org/ HTTP/1.1 Mobile Safari/200.36删除前15行的数据
[root@www.wulaoer.org wulaoer]# sed -i '1,15d' access.log [root@www.wulaoer.org wulaoer]# sed -n '1p' access.log 10.10.2.16 2020:02:14:18:16 200 http://www.wulaoer.org/ HTTP/1.1 Mobile Safari/200.36删除50行以后的所有数据
[root@www.wulaoer.org wulaoer]# sed -i '20,$d' access.log #删除20行以后的所有数据 [root@www.wulaoer.org wulaoer]# sed -n '20p' access.log #查看第二十行的数据已经没有了 [root@www.wulaoer.org wulaoer]# sed -n '19p' access.log 10.10.2.34 2020:02:14:18:34 200 http://www.wulaoer.org/ HTTP/1.1 Mobile Safari/200.36删除所有的空行
[root@www.wulaoer.org wulaoer]# sed -i '/^$/d' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '$=' wulaoer.txt #查看文件的最后一行行号 27 [root@www.wulaoer.org wulaoer]# sed -n '1,27p' wulaoer.txt nagios wulaoer wulaoer ruby wulaoer.org python3 运维服务 运维开发 jenkins Django 技术博客 mongodb mysql jenkins pinpoint zabbix nagios grafana cacti redis ES nginx php java prometheus apollo nacos spring dubbo删除行首空格的三种方法:
[root@localhost ~]# sed -i 's/^[[:space:]]*//g' wulaoer.txt [root@localhost ~]# sed -i 's/^[ ]*//g' wulaoer.txt [root@localhost ~]# sed -i 's/^ *//g' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -i 's/^[[:space:]]*//g' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '1,27p' wulaoer.txt nagios wulaoer wulaoer ruby wulaoer.org python3 运维服务 运维开发 jenkins Django 技术博客 mongodb mysql jenkins pinpoint zabbix nagios grafana cacti redis ES nginx php java prometheus apollo nacos spring dubbo删除所有包含wulaoer的行
[root@www.wulaoer.org wulaoer]# sed -i '/wulaoer/d' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '$=' wulaoer.txt 25 [root@www.wulaoer.org wulaoer]# sed -n '1,25p' wulaoer.txt nagios python3 运维服务 运维开发 jenkins Django 技术博客 mongodb mysql jenkins pinpoint zabbix nagios grafana cacti redis ES nginx php java prometheus apollo nacos spring dubbosed 命令处理换行符,例如替换或者删除
[root@www.wulaoer.org wulaoer]# sed ':label;N;s/\n/:/;b label' wulaoer.txt nagios:python3:运维服务:运维开发:jenkins:Django:技术博客:mongodb:mysql:jenkins:pinpoint:zabbix:nagios:grafana:cacti:redis:ES:nginx:php:java:prometheus:apollo:nacos:spring:dubbo [root@www.wulaoer.org wulaoer]# sed ':label;N;s/\n/:/;t label' wulaoer.txt nagios:python3:运维服务:运维开发:jenkins:Django:技术博客:mongodb:mysql:jenkins:pinpoint:zabbix:nagios:grafana:cacti:redis:ES:nginx:php:java:prometheus:apollo:nacos:spring:dubbo
[root@www.wulaoer.org wulaoer]# sed -i '1a www.wulaoer.org' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '2p' wulaoer.txt www.wulaoer.org在文件的第三行和第四行后面追加wulaoer.org
[root@www.wulaoer.org wulaoer]# sed -i '3,4a wulaoer.org' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '2,6p' wulaoer.txt www.wulaoer.org python3 wulaoer.org 运维服务 wulaoer.org在字符串python3后追加字符串"世界上最好的语言"
[root@www.wulaoer.org wulaoer]# sed -i '/python3/a 世界上最好的语言' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '1,5p' wulaoer.txt nagios个人技术博客 ruby.wulaoer.org python3 世界上最好的语言 ruby.wulaoer.org ruby wulaoer.orgnginx开头的行,在前面追加字符串"is web server"
[root@www.wulaoer.org wulaoer]# sed -i '/^nginx/i is web server' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '1,$p' wulaoer.txt ............. redis ES is web server nginx文件的每一行后面都加字符串:"wulaoer.org"
[root@www.wulaoer.org wulaoer]# sed -i 'a wulaoer.org' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '1,5p' wulaoer.txt nagios个人技术博客 wulaoer.org ruby.wulaoer.org wulaoer.org python3文件的最后一行追加字符串:"https://www.wulaoer.org"
[root@www.wulaoer.org wulaoer]# sed -i '$a https://www.wulaoer.org' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '$=' wulaoer.txt 63 [root@www.wulaoer.org wulaoer]# sed -n '63p' wulaoer.txt https://www.wulaoer.org创建文件jenkins.txt,以便下面的测试
[root@www.wulaoer.org wulaoer]# vim jenkins.txt jenkins install将jenkins.txt文件的内容追加到wulaoer.txt文件的第一行下
[root@www.wulaoer.org wulaoer]# sed -i '1r jenkins.txt' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '1,2p' wulaoer.txt nagios个人技术博客 jenkins install将jenkins.txt文件内容追加到wulaoer.txt 文件匹配到nginx行的后面
[root@www.wulaoer.org wulaoer]# sed -i '/nginx/r jenkins.txt' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '45,50p' wulaoer.txt wulaoer.org nginx jenkins install wulaoer.org php wulaoer.org将jenkins.txt文件内容追加到wulaoer.txt 文件中特定行后面,匹配以wulaoer开头的行,到第4行的所有行
[root@www.wulaoer.org wulaoer]# sed -i '/^wulaoer/,4r jenkins.txt' wulaoer.txt [root@www.wulaoer.org wulaoer]# sed -n '1,5p' wulaoer.txt nagios个人技术博客 jenkins install wulaoer.org jenkins install ruby.wulaoer.org将passwd文件匹配到wulaoer的行追加到jenkins.txt文件中
[root@www.wulaoer.org wulaoer]# sed -i '/wulaoer/w jenkins.txt' wulaoer.txt [root@www.wulaoer.org wulaoer]# cat jenkins.txt wulaoer.org ruby.wulaoer.org wulaoer.org wulaoer.org wulaoer.org将wulaoer.txt 文件从第10行开始,到匹配到wulaoer的所有行内容追加到jenkins.txt
[root@www.wulaoer.org wulaoer]# sed -i '10,/wulaoer/w jenkins.txt' wulaoer.txt [root@www.wulaoer.org wulaoer]# cat jenkins.txt wulaoer.org jenkins install 世界上最好的语言 wulaoer.org将文件wulaoer.txt 文件中匹配wulaoer和jenkins的行和内容写到jenkins.txt文件中。
[root@www.wulaoer.org wulaoer]# sed -n '/wulaoer\|jenkins/w jenkins.txt' wulaoer.txt [root@www.wulaoer.org wulaoer]# cat jenkins.txt jenkins install wulaoer.org jenkins install ruby.wulaoer.org将文件wulaoer.txt中的内容写入到wulaoer.txt 文件中
[root@www.wulaoer.org wulaoer]# sed -n 'w jenkins.txt' wulaoer.txt将文件wulaoer.txt 中的第二行内容写入到jenkins.txt文件中
[root@www.wulaoer.org wulaoer]# sed -n '2w jenkins.txt' wulaoer.txt将wulaoer.txt的第一行和最后一行内容写入到jenkins.txt中
[root@www.wulaoer.org wulaoer]# sed -n -e '1w jenkins.txt' -e '$w jenkins.txt' wulaoer.txt将wulaoer.txt 文件中的第一行和最后一行分别写入到1.txt和2.txt文件中
[root@www.wulaoer.org wulaoer]# sed -n -e '1w 1.txt' -e '$w 2.txt' wulaoer.txt将wulaoer.txt文件中匹配123的行到最后一行的内容下如到jenkins.txt文件中。
[root@www.wulaoer.org wulaoer]# sed -n '/123/,$w jenkins.txt' wulaoer.txt将wulaoer.txt 文件中匹配123的行以及后两行的内容下如到jenkins.txt文件中。
[root@www.wulaoer.org wulaoer]# sed -n '/123/,+2w jenkins.txt' wulaoer.txt
i: 插入,i前面是整数代表行业可以是范围,后面跟的是插入的字符串,代表在某一行或范围下面插入字符串。 d:删除,d前面是整数代表行也可以是范围,代表删除某一行或某一范围。 a: 新增,a前面是整数代表行也可以是范围,后面跟的是新增的字符串,代表在某一行或范围后面追加字符串。 c:取代,c前面是整数代表行也可以是范围,后面跟的是取代的字符串,代表在某一行或范围替换成后面的字符串。 s: 取代,通常在有参数的命令中,配合正则一起使用 p:打印,p前面是整数代表行也可以是范围,代表打印某一行或某一范围。以上这些动作,在不加参数的情况下,都不会对源文件进行更改。除s和p之外,因为这两个动作必须要配合参数才可以使用 我自己先创建了一个文本文件,然后在文件中加了一些关键词,下面的例子主要围绕这个文件进行操作:
[root@www.wulaoer.org ~]# cat wulaoer.txt nagios word python3 运维服务 运维开发 DevOps ruby Django golong学习 golong 技术博客 mongodb mysql在第二行插入关键词"吴老二",我们不使用参数,值使用动作操作,看一下加参数和不加参数的区别。
[root@www.wulaoer.org ~]# sed '2i 吴老二' test.txt nagios 吴老二 word python3 运维服务 运维开发 DevOps ruby Django golong学习 golong 技术博客 mongodb mysql这里的参数没有,只有动作"'2i 吴老二'",所以返回一个在第二行插入关键词的内容,但是没有写到文件中,如果想要写到文件中,需要增加参数"-i",这个在后面的参数i中有详细的描述。下面看一下
[root@www.wulaoer.org ~]# sed '2d' test.txt nagios python3 运维服务 运维开发 DevOps ruby Django golong学习 golong 技术博客 mongodb mysql这里的"2d"是删除的动作,如果删除多行可以在'd'前面加个范围,例如:sed '2,5d' test.txt 就是删除从第二到第五行,如果想删除6行一下的内容可以使用动作'6,$d'。没有写到文件中,同样如果增加参数'-i'就会在原文件中删除第二行的内容。
[root@www.wulaoer.org ~]# sed '2a 吴老二' test.txt nagios word 吴老二 python3 运维服务 运维开发 DevOps ruby Django golong学习 golong 技术博客 mongodb mysql'a'的动作是追加,是追加到某一行,不是在某一行后追加内容,范围和上面的一样。
[root@www.wulaoer.org ~]# sed '3,8c www.wulaoer.org' test.txt nagios wulaoer www.wulaoer.org Django golong学习 golong 技术博客 mongodb mysql以上是针对sed的用法,不足之处还需提出,虚心请教。
评论 0