Linux sed 命令

2023-11-09

简介

sed:Stream Editor文本流编辑,sed是一个“非交互式的”面向字符流的编辑器。能同时处理多个文件多行的内容,可以不对原文件改动,把整个文件输入到屏幕,可以把只匹配到模式的内容输入到屏幕上。还可以对原文件改动,但是不会再屏幕上返回结果。

sed 是一种在线编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有 改变,除非你使用重定向存储输出。Sed主要用来自动编辑一个或多个文件;简化对文件的反复操作;编写转换程序等。

sed的选项、命令、替换标记

选项

sed [options] '{command}[flags]' [filename]    
# 中括号内容必有 大括号内容可有可无
sed  # 执行命令
[options]  # 命令选项
{command}[flags]    # sed内部选项和参数
[filename]     # 文件
命令选项
-e script 将脚本中指定的命令添加到处理输入时执行的命令中,  多条件,一行中要有多个操作
-f script 将文件中指定的命令添加到处理输入时执行的命令中
-n        抑制自动输出
-i        编辑文件内容
-i.bak    修改时同时创建.bak备份文件。
-r        使用扩展的正则表达式
!         取反 (跟在模式条件后与shell有所区别)

sed常用内部命令
a   在匹配后面添加
i   在匹配前面添加
p   打印
d   删除
s   查找替换
c   更改
y   转换   N D P 

flags
数字             表示新文本替换的模式
g:             表示用新文本替换现有文本的全部实例
p:             表示打印原始的内容
w filename:     将替换的结果写入文件

 sed常用命令

 a\ 在当前行下面插入文本;
 
 i\ 在当前行上面插入文本;
 
 c\ 把选定的行改为新的文本;
 
 d 删除,删除选择的行;
 
 D 删除模板块的第一行;
 
 s 替换指定字符;
 
 h 拷贝模板块的内容到内存中的缓冲区;
 
 H 追加模板块的内容到内存中的缓冲区;
 
 g 获得内存缓冲区的内容,并替代当前模板块中的文本;
 
 G 获得内存缓冲区的内容,并追加到当前模板块文本的后面;
 
 l 列表不能打印字符的清单;
 
 n 读取下一个输入行,用下一个命令处理新的行而不是用第一个命令;
 
 N 追加下一个输入行到模板块后面并在二者间嵌入一个新行,改变当前行号码;
 
 p 打印模板块的行。 P(大写) 打印模板块的第一行;
 
 q 退出Sed;
 
 b lable 分支到脚本中带有标记的地方,如果分支不存在则分支到脚本的末尾;
 
 r file 从file中读行;
 
 t label if分支,从最后一行开始,条件一旦满足或者T,t命令,将导致分支到带有标号的命令处,或者到脚本的末尾;
 
 T label 错误分支,从最后一行开始,一旦发生错误或者T,t命令,将导致分支到带有标号的命令处,或者到脚本的末尾;
 
 w file 写并追加模板块到file末尾;
 
 W file 写并追加模板块的第一行到file末尾;
 
 ! 表示后面的命令对所有没有被选定的行发生作用;
 
 = 打印当前行号;
 
 # 把注释扩展到下一个换行符以前;

sed替换标记

 g 表示行内全面替换;
 
 p 表示打印行;
 
 w 表示把行写入一个文件;
 
 x 表示互换模板块中的文本和缓冲区中的文本;
 
 y 表示把一个字符翻译为另外的字符(但是不用于正则表达式);
 
 \1 子串匹配标记;
 
 & 已匹配字符串标记;

sed元字符集

 ^ 匹配行开始,如:/^sed/匹配所有以sed开头的行;
 
 $ 匹配行结束,如:/sed$/匹配所有以sed结尾的行;
 
 . 匹配一个非换行符的任意字符,如:/s.d/匹配s后接一个任意字符,最后是d;
 
 * 匹配0个或多个字符,如:/*sed/匹配所有模板是一个或多个空格后紧跟sed的行;
  
 [] 匹配一个指定范围内的字符,如/[ss]ed/匹配sed和Sed;
   
 [^] 匹配一个不在指定范围内的字符,如:/[^A-RT-Z]ed/匹配不包含A-R和T-Z的一个字母开头,紧跟ed的行;
  
 \(..\) 匹配子串,保存匹配的字符,如s/\(love\)able/\1rs,loveable被替换成lovers;
  
 & 保存搜索字符用来替换其他字符,如s/love/**&**/,love这成**love**;
  
 \< 匹配单词的开始,如:/\ 
 \> 匹配单词的结束,如/love\>/匹配包含以love结尾的单词的行;
 
 x\{m\} 重复字符x,m次,如:/0\{5\}/匹配包含5个0的行;
 
 x\{m,\} 重复字符x,至少m次,如:/0\{5,\}/匹配至少有5个0的行;
 
 x\{m,n\} 重复字符x,至少m次,不多于n次,如:/0\{5,10\}/匹配5~10个0的行;

示例操作

文件内容增加操作,将数据追加到某个位置之后,使用命令 a 。

    在指定行后面追加内容

在第二到四行每行后新开一行追加数据: append data “haha”

[root@jiangnan data]# sed '2,4a\append data "haha"' sed.txt
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
append data "haha"
3 the quick brown fox jumps over the lazy dog.
append data "haha"
4 the quick brown fox jumps over the lazy dog.
append data "haha"
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

    说明:a表示在匹配的行后面新开一行新增内容。2,4a表示第2到4行,如果不写数字,表示所有行。

    匹配字符串追加

找到包含"3 the"的行,在其后新开一行追加内容: append data “haha”

[root@jiangnan data]# sed '/3 the/a\append data "haha"' sed.txt
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
3 the quick brown fox jumps over the lazy dog.
append data "haha"
4 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

    这里注意:/要匹配的字符串/

    这种方法比较常用,匹配指定的字符串然后进行增加,比如XML文件等。

文件内容增加操作,将数据插入到某个位置之前,使用命令 i 。

    匹配字符串插入

找到包含"3 the"的行,在其前新开一行插入内容: insert data “haha”

[root@jiangnan data]# sed '/3 the/i\append data "haha"' sed.txt
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
append data "haha"
3 the quick brown fox jumps over the lazy dog.
4 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

    这里注意:/要匹配的字符串/

    使用方法同a类似。

文件内容修改操作—替换,将一行中匹配的内容替换为新的数据,使用命令s。

    在指定行后面追加内容

将sed.txt 中第二到第四行的dog替换为cat

[root@jiangnan data]# sed '2,4s/dog/cat/' sed.txt
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy cat.
3 the quick brown fox jumps over the lazy cat.
4 the quick brown fox jumps over the lazy cat.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

    匹配字符串所在行指定字符的替换

将包含字符串"3 the"的行中的dog替换为cat

[root@jiangnan data]# sed '/3 the/s/dog/cat/' sed.txt
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
3 the quick brown fox jumps over the lazy cat.
4 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

    这里注意:/匹配字符串所在的行/s/指定匹配字符串/要替换的字符串/

文件内容修改操作—更改,将一行中匹配的内容替换为新的数据,使用命令c。

    匹配行整行的替换

将sed.txt 文件中的第二、三、四行的内容更改为:change data “haha”

[root@jiangnan data]# sed '2,4c\change data haha' sed.txt
1 the quick brown fox jumps over the lazy dog.
change data haha
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

    匹配字符串所在行整行的替换

将sed.txt文件中包含"3 the"的行内容更改为: change data “haha”

[root@jiangnan data]# sed '/3 the/c\change data haha' sed.txt
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
change data haha
4 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

文件内容修改操作—字符转换,将一行中匹配的内容替换为新的数据,使用命令y。

    将sed.txt中的a b c字符转换为对应的 A B C字符

​

[root@jiangnan data]# sed 'y/abc/ABC/' sed.txt
1 the quiCk Brown fox jumps over the lAzy dog.
2 the quiCk Brown fox jumps over the lAzy dog.
3 the quiCk Brown fox jumps over the lAzy dog.
4 the quiCk Brown fox jumps over the lAzy dog.
5 the quiCk Brown fox jumps over the lAzy dog.
[root@jiangnan data]#

[点击并拖拽以移动]
​

文件内容删除,将文件中的指定数据删除,使用命令d。

    删除文件sed.txt 第三到第四行的数据

[root@jiangnan data]# sed '3,4d' sed.txt
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

文件内容查看,将文件内容输出到屏幕,使用命令p。

    打印sed.txt的内容

[root@jiangnan data]# sed 'p' sed.txt
1 the quick brown fox jumps over the lazy dog.
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
3 the quick brown fox jumps over the lazy dog.
3 the quick brown fox jumps over the lazy dog.
4 the quick brown fox jumps over the lazy dog.
4 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

    打印sed.txt文件包含字符串"3 the"的行

[root@jiangnan data]# sed '/3 the/p' sed.txt
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
3 the quick brown fox jumps over the lazy dog.
3 the quick brown fox jumps over the lazy dog.
4 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

    现象:可以看得出,打印内容是重复的行,原因是打印了指定文件内容一次,又将读入缓存的所有数据打印了一次,所以会看到这样的效果, 如果不想看到这样的结果,可以加命令选项-n抑制内存输出即可。

[root@jiangnan data]# sed -n '/3 the/p' sed.txt
3 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

 

命令选项说明

在命令行中使用多个命令 -e

    将brown替换为green dog替换为cat

[root@jiangnan data]# sed -e 's/brown/green/;s/dog/cat/' sed.txt
1 the quick green fox jumps over the lazy cat.
2 the quick green fox jumps over the lazy cat.
3 the quick green fox jumps over the lazy cat.
4 the quick green fox jumps over the lazy cat.
5 the quick green fox jumps over the lazy cat.
[root@jiangnan data]#

从文件读取编辑器命令 -f 适用于日常重复执行的场景

1)将命令写入文件
 

[root@jiangnan data]# vim abc.txt
[root@jiangnan data]# cat abc.txt
s/brown/green/
s/dog/cat/
s/fox/elephant/
[root@jiangnan data]#

2)使用-f命令选项调用命令文件

[root@jiangnan ~]# sed -f abc.txt sed.txt
1 the quick green elephant jumps over the lazy cat.
2 the quick green elephant jumps over the lazy cat.
3 the quick green elephant jumps over the lazy cat.
4 the quick green elephant jumps over the lazy cat.
5 the quick green elephant jumps over the lazy cat.
[root@jiangnan data]#

抑制内存输出 -n

    打印sed.txt文件的第二行到最后一行内容 $最后的意思

[root@jiangnan data]# sed -n '2,$p' sed.txt
2 the quick brown fox jumps over the lazy dog.
3 the quick brown fox jumps over the lazy dog.
4 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

使用正则表达式 -r

    打印sed.txt中以字符串"3 the"开头的行内容

在这里插入图片描述

    说明:在正则表达式中如果出现特殊字符(^$.*/[]),需要以前导 “\” 号做转义

注意:做完了上面的案例,但是我们发现源文件并没有任何改变,原因就是sed操作的是缓存区里的内容,对我们的源文件没有做改变。如果需要修改文件内容可以直接使用-i命令选项,-i命令选项提供了备份功能,比如参数使用-i.bak,那么在修改源文件的同时会先备份一个以.bak结尾的源文件,然后再进行修改操作。

[root@jiangnan data]# sed -i.bak 's/brown/green/' sed.txt
[root@jiangnan data]# cat sed.txt
1 the quick green fox jumps over the lazy dog.
2 the quick green fox jumps over the lazy dog.
3 the quick green fox jumps over the lazy dog.
4 the quick green fox jumps over the lazy dog.
5 the quick green fox jumps over the lazy dog.
[root@jiangnan data]# cat sed.txt.bak
1 the quick brown fox jumps over the lazy dog.
2 the quick brown fox jumps over the lazy dog.
3 the quick brown fox jumps over the lazy dog.
4 the quick brown fox jumps over the lazy dog.
5 the quick brown fox jumps over the lazy dog.
[root@jiangnan data]#

标志

准备数据

[root@jiangnan data]# vi sed2.txt
[root@jiangnan data]# cat sed2.txt
1 the quick brown fox jumps over the lazy dog . dog
2 the quick brown fox jumps over the lazy dog . dog
3 the quick brown fox jumps over the lazy dog . dog
4 the quick brown fox jumps over the lazy dog . dog
5 the quick brown fox jumps over the lazy dog . dog
[root@jiangnan data]#

    数字标志:此标志是一个非零正数,默认情况下,执行替换的时候,如果一行中有多个符合的字符串,如果没有标志位定义,那么只会替换第一个字符串,其他的就被忽略掉了,为了能精确替换,可以使用数字位做定义。

    替换一行中的第二处dog为cat

    对比有标志和没有标志的区别

g标志:将一行中的所有符合的字符串全部执行替换

    将包含3 the所在行中的dog替换为cat

[root@jiangnan data]# sed '/3 the/s/dog/cat/g' sed2.txt
1 the quick brown fox jumps over the lazy dog . dog
2 the quick brown fox jumps over the lazy dog . dog
3 the quick brown fox jumps over the lazy cat . cat
4 the quick brown fox jumps over the lazy dog . dog
5 the quick brown fox jumps over the lazy dog . dog
[root@jiangnan data]#

    ‘g’表示global,全部替换

p标志:打印文本内容,类似于-p命令选项

[root@jiangnan data]# sed '3s/dog/cat/p' sed2.txt
1 the quick brown fox jumps over the lazy dog . dog
2 the quick brown fox jumps over the lazy dog . dog
3 the quick brown fox jumps over the lazy cat . dog
3 the quick brown fox jumps over the lazy cat . dog
4 the quick brown fox jumps over the lazy dog . dog
5 the quick brown fox jumps over the lazy dog . dog
[root@jiangnan data]# 

w filename标志:将修改的内容存入filename文件中

[root@jiangnan data]# sed '3s/dog/cat/w sed3.txt' sed2.txt
1 the quick brown fox jumps over the lazy dog . dog
2 the quick brown fox jumps over the lazy dog . dog
3 the quick brown fox jumps over the lazy cat . dog
4 the quick brown fox jumps over the lazy dog . dog
5 the quick brown fox jumps over the lazy dog . dog
[root@jiangnan data]# cat sed3.txt
3 the quick brown fox jumps over the lazy cat . dog
[root@jiangnan data]#

    可以看出,将修改的第三行内容存在了sed3.txt文件中

三、sed小技巧

统计data2有多少行
[root@jiangnan ~]# sed -n '$=' data2
5

打印data2内容时加上行号
 

[root@jiangnan ~]# sed  '=' data2
1
1 the quick brown fox jumps over the lazy dog . dog
2
2 the quick brown fox jumps over the lazy dog . dog
3
3 the quick brown fox jumps over the lazy dog . dog
4
4 the quick brown fox jumps over the lazy dog . dog
5
5 the quick brown fox jumps over the lazy dog . dog

输出包含the的所在行的行号(= 用来输出行号)
[root@jiangnan ~]# sed -n '/the/=' test.txt

输出以PI开头的行
[root@jiangnan ~]# sed -n '/^PI/p' test.txt

输出以数字结尾的行
[root@jiangnan ~]# sed -n '/[0-9]$/p' test.txt

输出包含单词wood的行 \< ,\>表示单词边界
[root@jiangnan ~]# sed -n '/\<wood\>/p' test.txt
a wood cross!

每行开始添加#字符    
[root@jiangnan ~]# sed 's/^/#/' test.txt

在包含the的每行行首添加#字符
[root@jiangnan ~]# sed '/the/s/^/#/' test.txt

在每行末尾添加EOF字符
[root@jiangnan ~]# sed 's/$/EOF/' test.txt

将3-5行所有的the替换为THE          
[root@jiangnan ~]# sed '3,5s/the/THE/g' test.txt

将包含the的行中的o替换为O    
[root@jiangnan ~]# sed '/the/s/o/O/g' test.txt

迁移符合条件的文本
H 复制到剪贴板;
g,G 将剪贴板中的数据覆盖/追加到指定行;
w保存为文件;
r读取指定文件;
a 追加指定内容

将包含the的行迁移到行尾(;用于多个操作)

H复制到剪贴板---d删除---$G追加到行尾
[root@jiangnan ~]# sed '/the/{H;d};$G' test.txt

将1-5行迁移到17行后
[root@jiangnan ~]# sed '1,5{H;d};17G' test.txt

将包含the的行另存为新文件
[root@jiangnan ~]# sed '/the/w out.file' test.txt

[root@jiangnan ~]# ls

anaconda-ks.cfg  out.file  test.txt  :wq

[root@jiangnan ~]# cat out.file

在包含the每行后添加文件hostname内容
[root@jiangnan ~]# sed '/the/r /etc/hostname' test.txt

在第3行后插入新行,内容为New
[root@jiangnan ~]# sed '3aNew' test.txt

在包含the的每行后插入新行        
[root@jiangnan ~]# sed '/the/aNew' test.txt

在第3行后插入多行(\n 换行符)
[root@jiangnan ~]# sed '3aNew1\nNew2' test.txt
ngnan ~]# sed '1,5{H;d};17G' test.txt

将包含the的行另存为新文件
[root@jiangnan ~]# sed '/the/w out.file' test.txt

[root@jiangnan ~]# ls

anaconda-ks.cfg  out.file  test.txt  :wq

[root@jiangnan ~]# cat out.file

在包含the每行后添加文件hostname内容
[root@jiangnan ~]# sed '/the/r /etc/hostname' test.txt

在第3行后插入新行,内容为New
[root@jiangnan ~]# sed '3aNew' test.txt

在包含the的每行后插入新行        
[root@jiangnan ~]# sed '/the/aNew' test.txt

在第3行后插入多行(\n 换行符)
[root@jiangnan ~]# sed '3aNew1\nNew2' test.txt

 

 参考:

Linux之sed命令详解 - zakun - 博客园

【Linux篇】sed命令详解_傻啦猫@_@的博客-CSDN博客_linux sed命令

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux sed 命令 的相关文章

随机推荐

  • SpringBoot + MyBatisPlus + MySQL8 实现树形结构查询

    场景 今天在实现权限功能模块时 需要将查询的权限数据 以树形结构的方式返回给前端 功能实现 第一步 权限表结构定义及其功能演示数据 DROP TABLE IF EXISTS baoan privilege CREATE TABLE baoa
  • 3_Docker 常用命令

    进程命令 启动docker服务 systemctl start docker 停止docker服务 systemctl stop docker 重启docker服务 systemctl restart docker 查看docker服务状态
  • 手把手教你 在linux上安装kafka

    目录 1 准备服务器 2 选一台服务器配置kafka安装包 2 1 下载安装包 2 2 解压安装包 2 3 修改配置文件 3 分发安装包到其他机器 4 修改每台机器的broker id 5 配置环境变量 6 启停kafka服务 6 1 启动
  • Linux之RedHat 7 图形界面版安装(转载)

    linuxLinux之RedHat 7 图形界面版安装的详细教程 点击跳转 转载 https blog csdn net star in shy article details 82590241
  • 进程控制块和状态——随堂笔记

    1 PCB 描述进程的数据结构 当一个进程创建以后交给操作系统管理 管理的时候要对进程的属性进行描述 1 进程的描述信息 进程的基本信息pid给每个进程的编号 名字 2 处理器状态信息 在进程执行过程中使用的处理器的各种寄存器的信息 原因
  • Linux下的时间(ZZ)

    1 Linux下的时间 1 1 Linux下的时间系统 1 2 Linux下与时间有关的数据结构 2 获得当前时间 3 延时 4 定时器 4 1 alarm 4 2 setitimer 1 Linux下的时间1 1 Linux下的时间系统
  • Linux CentOS 巡检脚本

    系统巡检脚本 有常用的检查模块 如硬盘 内存 进程等 安全性检查等 1 巡查脚本 代码如下 示例 xunjian sh bin bash 系统状态 host while do clear echo e 当前在查看 e 1 31m 主机状态信
  • 永洪科技入选“2023大数据优秀服务商”

    8月23日 2023大数据优秀服务商 发布 永洪科技入选 此次评选由DBC CIS CIW eNet研究院牵头组织 旨在遴选大数据产业各细分赛道具有代表性与创新力的企业 组织 并展现其独特价值 重点考量技术实力 业内口碑 成长性 品牌力以及
  • LeetCode 5910. 检查两个字符串是否几乎相等

    如果两个字符串 word1 和 word2 中从 a 到 z 每一个字母出现频率之差都 不超过 3 那么我们称这两个字符串 word1 和 word2 几乎相等 给你两个长度都为 n 的字符串 word1 和 word2 如果 word1
  • Vue项目封装div拖动组件,实现div拖拽

    场景 在pc端项目中会碰到弹框后多个页面重叠的场景 类似于电脑打开多个文件夹 这时想要同时完整的展示两个页面的内容 就可以拖动页面 改变位置 很多教程都是使用自定义方法在单个组件中使用 本文带大家在Vue项目中封装一个拖拽div的方法 注册
  • JavaScript 弹窗

    JavaScript弹窗是Web开发中常见的交互方式之一 弹窗可以为用户提供提示 警告或者输入框等交互方式 让用户在使用网站或应用时更加便捷 在本文中 我们将讨论JavaScript弹窗的作用 类型和用途 JavaScript弹窗的作用 J
  • JVM的核心内容

    1 JVM对于java程序员的重要性可以用一下两句话来概述 1 1 关于任何java的技术问题都可以追溯到java虚拟机里面去 1 2 一个Java程序员水平的高低就看你对Java虚拟机这个东西有多了解 2 了解JVM需要先理解jdk与jr
  • 华为某高管工资曝光:每月高达27万,众网友表示长了见识

    如果说一个人工资每个月好几万 估计很多网友都会认为很高了 能拿到这么高薪资的人肯定是非常优秀和有能力的人 近日 一名在某企业从事招聘工作的网友在网上曝光了一条内容 其称在招聘简历中 无意发现了一份华为高管的简历 其级别是21级 月工资高达2
  • 利用Fiddler 解SSL加密 数据包

    在开发互联网应用的过程中 常常会设立或利用网络接口 为了调试对网络接口的使用 往往需要查看流入和流出网络接口的网络流量或数据包 抓包工具 就是一类用于记录通过网络接口的数据的工具 我们知道 网络协议是分层设计的 OSI模型将网络协议分为了7
  • 字符串之KMP详解

    昨晚梳理了一下KMP的过程 感觉印象深刻了不少 在此写下博客加深印象 同时也希望能和大家交流 KMP这个名字来源于其三个创始人名字首字母 主要用于解决字符串的匹配问题 字符串的匹配问题 假设有两个字符串S和T 问串T是否出现在串S中 串T在
  • Linux 链路聚合之bond和team

    交换机可以配置链路聚合 提供线路的冗余的同时提高带宽吞吐 服务器也可以通过bond team技术做网口硬件层面的冗余 防止单个网口应用的单点故障以及提高带吞吐量 bond模式最多可以添加两块网卡 team模式最多可以添加八块网卡 一 bon
  • vmware详细安装教程

    1 打开下载好的VMware安装文件 点击下一步 2 勾选 我接受许可协议中的条款 点击下一步 3 勾选 自动安装Windows Hypervisor Platform WHP 点击下一步 4 以下两个选项都勾选 5 选择安装路径 更改默认
  • TCP/IP协议三次握手与四次挥手

    一 标志位和序号 seq序号 发送方随机生成的 ack确认序号 ack seq 1 标志位ACK 1时确认序号有效 SYN标志位 发起一个新连接 ACK标志位 确认序号有效 FIN标志位 断开连接 二 三次握手 三次握手是客户端与服务端建立
  • 搭建 Github Pages 个人博客网站

    文章出自个人博客https knightyun github io 2018 04 01 github pages blog 1 1 转载请申明 目录 引言 关于博客 关于Github 创建Github账号 创建仓库 填充仓库 配置Gith
  • Linux sed 命令

    简介 sed Stream Editor文本流编辑 sed是一个 非交互式的 面向字符流的编辑器 能同时处理多个文件多行的内容 可以不对原文件改动 把整个文件输入到屏幕 可以把只匹配到模式的内容输入到屏幕上 还可以对原文件改动 但是不会再屏