网站建设项目招标公告,备案网站名称注意事项,全国企业信用信息公示系统辽宁,聊城市东昌府区建设路小学网站##################################################### sed命令来自英文词组stream editor的缩写#xff0c;其功能是利用语法/脚本对文本文件进行批量的编辑操作。sed命令最初由贝尔实验室开发#xff0c;后被众多Linux系统集成#xff0c;能够通过正则表达式对文件进行批…##################################################### sed命令来自英文词组stream editor的缩写其功能是利用语法/脚本对文本文件进行批量的编辑操作。sed命令最初由贝尔实验室开发后被众多Linux系统集成能够通过正则表达式对文件进行批量编辑让重复性的工作不再浪费时间。 参数
-i 不在终端显示 直接修改
-n 仅显示处理后的结果#########################
cat test1219.txt
a b c d e f g
h i j k l m n
o p q
r s t
u v w x y z
tttttttttttttttttttttttt
zhangsan____
wangwu
zhangzhangzhang把新的字符替换旧的字符 其中 s/new/old/gi 其中 i 表示忽略大小写
sed -i s/tttttttttttttttttttttttt/zhangsan____/gi ./test1219.txtcat test1219.txt
a b c d e f g
h i j k l m n
o p q
r s t
u v w x y z
zhangsan____
zhangsan____
wangwu
zhangzhangzhang#####################################################
删除指定字符串cat test1219.txt
a b c d e f g
h i j k l m n
o p q
r s t
u v w x y z
少壮不努力老大徒伤悲
少壮不努力老大徒伤悲
wangwu
zhangzhangzhangsed -i /少壮不努力老大徒伤悲/d ./test1219.txtcat test1219.txt
a b c d e f g
h i j k l m n
o p q
r s t
u v w x y z
wangwu
zhangzhangzhang#在第5行新增 数据 -e xiyyyy file 在文件file第x行 插入yyyy数据
# 下面这两个 都是等价的 重点是后者可以插入多行数据
sed -i -e 5ihello world this new line ./test1219.txtsed -i -e 5i\
hello world this new line ./test1219.txt
# 这个就是插入 字符 hello world this new line
sed -i -e 5ihello world this new line ./test1219.txt#替换2-5行的数据内容
sed 2,5c NewSentence test1219.txt
a b c d e f g
NewSentence
hello world this new line
hello world this new line
u v w x y z
wangwu
zhangzhangzhang#读取1-2 两行
sed -n 1,2p test1219.txt
a b c d e f g
h i j k l m n
##################################################### xargs英文全拼 eXtended ARGuments是给命令传递参数的一个过滤器也是组合多个命令的一个工具。 xargs 可以将管道或标准输入stdin数据转换成命令行参数也能够从文件的输出中读取数据。
xargs 也可以将单行或多行文本输入转换为其他格式例如多行变单行单行变多行。
xargs 默认的命令是 echo这意味着通过管道传递给 xargs 的输入将会包含换行和空白不过通过 xargs 的处理换行和空白将被空格取代。
###################
# 五个元素 一行输入
cat test1219.txt | xargs -n5
a b c d e
f g h i j
k l m n o
p q r s t
u v w x y
z
#############################
参考1
参考2
####################################### 写的有点乱 后面逐步完善 sed 命令 很重要 配上 正则 无敌