怎么把网站挂在服务器,wordpress底部怎么改,高端网站建设的流程是什么,上海建设工程招投标网站sed
grep就是查找文本当中的内容#xff0c;扩展正则表达式。
一、sed
1.1、sed的定义
sed是一种流编辑器#xff0c;一次处理一行内容。
如果只是展示#xff0c;会放在缓冲区#xff08;模式空间#xff09;#xff0c;展示结束#xff0c;会从模式空间把结果删除…sed
grep就是查找文本当中的内容扩展正则表达式。
一、sed
1.1、sed的定义
sed是一种流编辑器一次处理一行内容。
如果只是展示会放在缓冲区模式空间展示结束会从模式空间把结果删除。
一行一行处理处理完当前行才会处理下一行直到文件末尾。
1.2、sed的命令格式和操作选项
sed -e ‘操作符’ -e ‘操作符’ 文件1 文件2
-e表示可以跟多个操作符只有一个操作-e可以省略这里的-e是指定操作。
sed -e ‘操作符1;操作符2’ 文件1 文件2
1.2.1、选项
-e用于执行多个操作
-f 在脚本中定义好了操作符然后根据脚本内容的操作符对文件进行操作。
-i 直接修改目标文件慎用
-n仅显示script处理后的结果不加-nsed会有两个输出结果加了-n就会把默认输出屏蔽只显示一个结果。
1.2.2、操作符
p打印结果
r扩展正则表达式
s替换替换字符串
c替换替换行
y替换替换单个字符串多个字符替换必须和替换内容的字符长度保持一致。
d删除删除行
a增加在指定行的下一行插入内容
[rootlocalhost opt]# cat -n test1 | sed /ddd/a aai增加 在指定行上一行插入内容
[rootlocalhost opt]# cat -n test1 | sed /ddd/i aar插入文本内容
[rootlocalhost opt]# cat -n test1 | sed /ddd/r test2 $a在最后一行下一行插入新的内容
[rootlocalhost opt]# cat -n test1 | sed $a sdsddsds12343 $i在最后一行上一行插入新的内容
[rootlocalhost opt]# cat -n test1 | sed $i sdsddsds12343 $r在最后一行下一行插入文本内容
[rootlocalhost opt]# cat -n test1 | sed $r test2 1.2.3、打印功能
1.2.3.1、寻址打印
行号打印
[rootlocalhost opt]# sed -n ;p test1打印第四行
[rootlocalhost opt]# sed -n 4p test1打印最后一行
[rootlocalhost opt]# sed -n $p test1显示行号
[rootlocalhost opt]# cat -n test1 | sed -n p 1.2.3.2、行号范围打印
打印第二到最后一行
[rootlocalhost opt]# sed -n 2,$p test1打印第二最后一行
[rootlocalhost opt]# sed -n 2p;$p test1
123
ddd打印奇数行和偶数行
打印偶数行n跳过第一行
[rootlocalhost opt]# cat -n test1 | sed -n n;p打印奇数行n跳过第一行
[rootlocalhost opt]# cat -n test1 | sed -n p;n n的作用跳过一行打印下一行。
1.2.4、文本内容进行过滤
过滤并打印包含o的行/过滤内容/
[rootlocalhost opt]# cat -n test1 | sed -n /z/p ##/过滤内容/13 zzz26 zzz使用正则表达式对文本内容进行过滤
[rootlocalhost opt]# cat /etc/passwd | sed -n /^a/p
adm:x:3:4:adm:/var/adm:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin从指定行开始打印到第一个以bash为结尾的行
[rootlocalhost opt]# cat /etc/passwd | sed -n 3,/bash$/p扩展正则表达式 [rootlocalhost opt]# cat /etc/passwd | sed -rn /(99:){2,}/p
nobody:x:99:99:Nobody:/:/sbin/nologin要么以root开头要么以bash结尾
[rootlocalhost opt]# cat /etc/passwd | sed -rn /\broot|bash\b/p 面试题1
如何免交互删除文本内容。不删除文件
sed 删除文件内容
[rootlocalhost opt]# sed -i d test2
[rootlocalhost opt]# cat test2
[rootlocalhost opt]# cat /dev/null 删除文件内容
[rootlocalhost opt]# cat test2
12
ewdsdds
f
d
fd
f
g[rootlocalhost opt]# cat /dev/null test2
[rootlocalhost opt]# cat test2sed的删除操作
删除指定行
[rootlocalhost opt]# cat -n test1 | sed -n 3d;p 1 1232 1234 345删除25到最后一行
[rootlocalhost opt]# cat -n test1 | sed -n 25,$d;p 删除指定x行
[rootlocalhost opt]# cat -n test1 | sed -n x!d;p 除了4-6行其他全部删除
[rootlocalhost opt]# cat -n test1 | sed -n 4,6!d;p 4 3455 3456 匹配字符串删除行 面试题2
如何免交互的方式删除空行 [rootlocalhost opt]# grep -v ^$ test1[rootlocalhost opt]# cat test1 | tr -s \n[rootlocalhost opt]# sed /^$/d test1s替换字符串----加g全部替换
sed -n ‘s/需要替换/替换成/gp’
[rootlocalhost opt]# cat /etc/passwd | sed -n s/root/test/p
test:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/test:/sbin/nologin
[rootlocalhost opt]# cat /etc/passwd | sed -n s/root/test/gp
test:x:0:0:test:/test:/bin/bash
operator:x:11:0:operator:/test:/sbin/nologin[rootlocalhost opt]# cat -n test1 | sed -n s/^/#/gp # 1 123# 2 # 3 # 4 123[rootlocalhost opt]# cat -n test1 | sed -n 4p;5p | sed -n s/^/#/gp # 4 123 ##打印后注释# 5 [rootlocalhost opt]# cat -n test1 | sed -n 4s/^/#/gp;6s/^/#/gp # 4 123# 6 123首字母变大写------加g是全部
[rootlocalhost opt]# cat -n test1 | sed s/[a-z]/\u/ u转换首字母大写的特殊符号\转义符。
[rootlocalhost opt]# cat -n test1 | sed s/[a-z]/\u/g 12 23413 34514 AAA15 BBB16 ZZZ17 QQQ18 QQQ19 ZZZ20 SSS21 AAA22 DDD23 DDD12324 34525 234首字母变小写—加g是全部
l转换首字母大写的特殊符号\转义符。
[rootlocalhost opt]# cat -n test1 | sed s/[A-Z]/\l/g 13 34514 aaa15 bbb16 zzz17 qqq18 qqq19 zzz20 sss21 aaa22 ddd23 ddd12324 34525 23426 34527 aaa28 bbb29 zzz30 zzz31 sss32 aaa
整行替换
[rootlocalhost opt]# cat -n test1 | sed /123/c dn zhen de shuai[rootlocalhost opt]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 | sed /IPADDR192.168.168.10/c /IPADDR192.168.168.100
TYPEEthernet
DEVICEens33
ONBOOTyes
BOOTPROTOstatic
/IPADDR192.168.168.100y,单字符替换
[rootlocalhost opt]# cat -n test1 | sed y/abc/678/r插入文本内容
[rootlocalhost opt]# cat -n test1 | sed /ddd/r test2 $a在最后一行下一行插入新的内容
[rootlocalhost opt]# cat -n test1 | sed $a sdsddsds12343 $i在最后一行上一行插入新的内容
[rootlocalhost opt]# cat -n test1 | sed $i sdsddsds12343 $r在最后一行下一行插入文本内容
[rootlocalhost opt]# cat -n test1 | sed $r test2 使用sed对字符串和字符的位置进行互换。
[rootlocalhost opt]# echo chengqianshuai | sed -r s/(cheng)(qian)(shuai)/\3\1\2/
shuaichengqian字符位置互换----使用.任意单字符代替
[rootlocalhost opt]# echo cheng | sed -r s/(.)(.)(.)(.)(.)/\4\5\3\1\2/
ngech面试题3
筛选安装版本号
ant-1.9.7.jar
ant-launcher-1.9.7.jar
antlr-2.7.7.jar
antlr-runtime-3.4.jar
aopalliance-1.0.jar
archaius-core-0.7.6.jar
asm-5.0.4.jar
aspectjweaver-1.9.5.jar
bcpkix-jdk15on-1.64.jar
bcprov-jdk15-1.46.jar
bcprov-jdk15on-1.64.jar
checker-compat-qual-2.5.5.jar[rootlocalhost opt]# cat test1.txt | sed -r s/(.*)-(.*)(\.jar)/\2/
1.9.7
1.9.7
2.7.7
3.4
1.0
0.7.6
5.0.4
1.9.5
1.64
1.46
1.64
2.5.5[rootlocalhost opt]# cat test1.txt | egrep -o \b([0-9][.][0-9][0-9])|\b([0-9][.][0-9][.][0-9])
1.9.7
1.9.7
2.7.7
0.7.6
5.0.4
1.9.5
1.64
1.46
1.64
2.5.5打印指定时间内的日志
[rootlocalhost opt]# tail /var/log/messages | sed -n /Jun 21 13:01:01/,/Jun 21 14:00:01/psed的主要作用是对文本的内容进行增删改查
其中最好用的最强大的是改和增。
作业
使用脚本的形式结合sed命令把pxe自动装机做一个自动化装机做一个自动化部署的脚本。 )(.jar)/\2/’ 1.9.7 1.9.7 2.7.7 3.4 1.0 0.7.6 5.0.4 1.9.5 1.64 1.46 1.64 2.5.5 [rootlocalhost opt]# cat test1.txt | egrep -o “\b([0-9][.][0-9][0-9])|\b([0-9][.][0-9][.][0-9])” 1.9.7 1.9.7 2.7.7 0.7.6 5.0.4 1.9.5 1.64 1.46 1.64 2.5.5 打印指定时间内的日志
[rootlocalhost opt]# tail /var/log/messages | sed -n ‘/Jun 21 13:01:01/,/Jun 21 14:00:01/p’ sed的主要作用是对文本的内容进行增删改查其中最好用的最强大的是改和增。# 作业使用脚本的形式结合sed命令把pxe自动装机做一个自动化装机做一个自动化部署的脚本。