首页 > 其他分享 >四剑客sed

四剑客sed

时间:2024-09-10 21:03:31浏览次数:1  
标签:00 Kylin V10 sp3 剑客 test sed root

find
grep/egrep -i -n -E -v -o -l
sed
awk

1. sed命令查找⭐⭐⭐⭐⭐

1.1 根据行号进行过滤

# -n 取消sed命令的默认输出
# p输出print

[root@Kylin-V10-sp3 ~/test]# sed -n '3p' /etc/passwd
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@Kylin-V10-sp3 ~/test]# 

1.2 根据行号范围进行过滤

#从第1行开始到第3行结束
[root@Kylin-V10-sp3 ~/test]# sed -n '1,3p' /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@Kylin-V10-sp3 ~/test]# 

#从第20行到最后一行
[root@Kylin-V10-sp3 ~/test]# sed -n '20,$p' /etc/passwd
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
dbus:x:81:81:D-Bus:/var/run/dbus:/sbin/nologin
polkitd:x:996:993:User for polkitd:/:/sbin/nologin

#文件最后一行
[root@Kylin-V10-sp3 ~/test]# sed -n '$p' /etc/passwd
nginx:x:990:986:Nginx web server:/var/lib/nginx:/sbin/nologin
[root@Kylin-V10-sp3 ~/test]# 

1.3 类似于grep/egrep进行过滤

#过滤指定内容 //
[root@Kylin-V10-sp3 ~/test]# sed -n '/root/p' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@Kylin-V10-sp3 ~/test]# 
#使用正则 记得加上-r
[root@Kylin-V10-sp3 ~/test]# sed -nr '/root|xk/p' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@Kylin-V10-sp3 ~/test]#

1.4 取出文件中某个范围的内容

# seq 3 25 >num.txt
# 从包含5的行到包含15的行
[root@Kylin-V10-sp3 ~/test]# seq 3 25 >num.txt
[root@Kylin-V10-sp3 ~/test]# 
# 多个25,/5/匹配配到了25中5,找不到包含15的数字就会一直找到文件最后。
[root@Kylin-V10-sp3 ~/test]# sed -n '/5/ , /15/p' num.txt 
5
6
7
8
9
10
11
12
13
14
15
25
[root@Kylin-V10-sp3 ~/test]# sed -n '/^5/ , /^15/p' num.txt 
5
6
7
8
9
10
11
12
13
14
15
[root@Kylin-V10-sp3 ~/test]# 

日志处理案例access.log过滤出 11点00分开始到11:10分结束的日志
温馨提示:

标签:00,Kylin,V10,sp3,剑客,test,sed,root
From: https://www.cnblogs.com/daofaziran/p/18407020

相关文章

  • 【pom】解决jar冲突心得 之 通过解决启动报错  Caused by: java.lang.NoClassDefFoun
     解决jar冲突心得之通过解决启动报错 Causedby:java.lang.NoClassDefFoundError:Couldnotinitializeclasscom.fasterxml.jackson.databind.ObjectMapper 学思路 一般情况,出现Causedby:java.lang.NoClassDefFoundError的问题1.要么是jar没有引入pom,所以找不......
  • 四剑客_正则
    1四剑客1.1概述1.2find命令基本用法1.2.1找出/etc/目录下面以.conf结尾的文件⭐⭐⭐⭐⭐[root@Kylin-V10-sp3~/test]#find/etc/-typef-name*.conf|head-5/etc/resolv.conf/etc/dnf/protected.d/systemd.conf/etc/dnf/protected.d/sudo.conf/etc/dnf/protect......
  • Shell编程:文本处理器(sed)
    文章目录sed编辑器工作过程提高sed执行效率的方法sed命令格式与选项地址定界sed的核心功能打印功能(p,=,l命令)删除操作(d命令)替换操作(s,c,y命令)增加功能(a,i,r命令)使用-f指定命令文件(读取规则)sed编辑器sed是一种流编辑器(StreamEdit......
  • MGT2IMG Australian-based renewable energy
    Assessment2–GroupAssessmentforMGT2IMGType: GroupReportGroupsize: 3studentseachDocument: MSWordwith12fontsizeand1.5spacingWordcount: 1,000perstudent(10+/-allowed)Referencingstyle.: APA7/8Weight: 30%Due: Sunday,29.09.202......
  • 读倪元璐书法--剑客龙天,时成花女
       “骨清年少眼如冰,凤羽参差五色层”,以杜甫诗意起笔评论读倪元璐书法未尚不可,明代末年的社会形势可以说是江河日下,许多忠臣义士,完成其最后的表演,黄道周、倪元璐等,以中原人固有的品格节操,照亮人间,他们的书法墨迹,又是让后来者窥探其忠心的媒介,书为心画,字中表露出来的迹......
  • grep sed awk cut组合使用
    以下是20个grep、sed、awk和cut的组合使用示例,以及每个命令执行过程的解释:1.使用grep查找并cut提取字段grep"error"logfile.txt|cut-d''-f2解释:查找logfile.txt中包含"error"的行,并提取每行以空格为分隔符的第二个字段。2.使用grep和sed替换文本gr......
  • 《赛博朋克2077》游戏启动时闪退提示“缺少ucrtbased.dll文件”该如何解决?赛博朋克207
    在启动《赛博朋克2077》时,若出现闪退并提示“缺少ucrtbased.dll文件”,确实让人头疼。但别慌张,这个问题是能够解决的。您可以尝试重新安装相关运行库,或者从可靠渠道获取该文件并放置到指定位置。具体该怎么操作?本篇将为大家带来《赛博朋克2077》游戏启动时闪退提示“缺少ucrtbas......
  • 网站提示“Connection refused:数据库连接被拒绝”错误如何解决
    当您遇到“Connectionrefused:数据库连接被拒绝”的错误时,这意味着您的应用程序尝试连接数据库时未能成功建立连接。这种错误通常由以下几种原因造成:数据库服务未启动:确认数据库服务(如MySQL、PostgreSQL等)正在运行。您可以在服务器上使用命令行工具检查服务的状态,例如对于MyS......
  • 高通平台功耗 - How_to_determine_wakeup_trigger_from_suspend_caused_by_PMIC_IRQ
    [366.151054]gic_show_resume_irq:222triggeredThisdebugmessageinthekernellogindicatesthataPMICSPMIIRQwasthewakeuptriggerfromsuspend.Toenableadditionaldebugmessageprintingusethefollowingcmds.adbrootadbwait-for-devicesa......
  • 11.吐血整理sed入门到精通,sed语法,脚本命令,打印,替换,删除,插入,行替换,字符替换,保
    文章目录前言sed介绍1.sed介绍2.sed语法介绍3.sed脚本命令1.打印2.s替换3.删除脚本命令d3.插入脚本命令a/i4.行替换脚本命令c4.字符替换脚本y5.保存内容脚本w6.插入其他文本r6.中断退出脚本命令q脚本命令当中的地址[address]正则表达式sed[选项]1.sed-i选项2.sed-e......