SED LEARN NOTE

时间:2021-02-28 00:11:42   收藏:0   阅读:29

SED LEARN NOTE

参考资料

SED LEARN NOTE

sed基本格式

#options

-e<script>或--expression=<script>:以选项中的指定的script来处理输入的文本文件;
-f<script文件>或--file=<script文件>:以选项中指定的script文件来处理输入的文本文件;
-h或--help:显示帮助;
-n或--quiet或——silent:仅显示script处理后的结果;
-V或--version:显示版本信息。

sed -f

sed -e

$ sed ‘1,3s/my/your/g; 3,$s/This/That/g‘ my.txt
This is your cat, your cat‘s name is betty
This is your dog, your dog‘s name is frank
That is your fish, your fish‘s name is george
That is my goat, my goat‘s name is adam
#第一种

sed -e ‘command1‘ -e ‘command2‘ input-file
#第二种

sed -e		`command1`	`command2`	input-file
#第三种

sed ‘command1;command2‘ input-file

#sed and awk hack 101

sed [options] ‘{
sed-command-1
sed-command-2
}’ input-file

sed打印命令

sed ‘p’结果

技术分享图片

上述处理方式会打印文本两次

sed -n ‘p’ result

-n或--quiet或——silent:仅显示script处理后的结果

技术分享图片

打印指定范围

#input-file

Lina is a good girl
Lina will be someones wife
Lina love anime
Lina will get a good job
Lina will live a happy life
Lina,see you again

打印指定行

技术分享图片

打印指定范围文本

技术分享图片

打印某行及其后几行

技术分享图片

打印奇数行

技术分享图片

打印匹配

打印匹配字符行

技术分享图片

打印第一次匹配字符至第num行,如果前面未匹配到字符则从后面找并匹配打印

打印第一次匹配字符至第num行

技术分享图片

打印匹配pattern1到匹配pattern2行间的内容

技术分享图片

打印匹配到的pattern及其后num行

技术分享图片

原文:https://www.cnblogs.com/movit/p/14457134.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!