Copyright © 2004,2005, 本文遵从GNU 的自由文档许可证(Free Document License)的条款,欢迎转载、修改、散布。
最近更新:2005年12月22日,增加小技巧章节。
sed 是一种在线编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有 改变,除非你使用重定向存储输出。Sed主要用来自动编辑一个或多个文件;简化对文件的反复操作;编写转换程序等。以下介绍的是Gnu版本的Sed 3.02。
可以通过定址来定位你所希望编辑的行,该地址用数字构成,用逗号分隔的两个行数表示以这两行为起止的行的范围(包括行数表示的那两行)。如1,3表示1,2,3行,美元符号($)表示最后一行。范围可以通过数据,正则表达式或者二者结合的方式确定 。
调用sed命令有两种形式:
-
a\
-
在当前行后面加入一行文本。
-
b lable
-
分支到脚本中带有标记的地方,如果分支不存在则分支到脚本的末尾。
-
c\
-
用新的文本改变本行的文本。
-
d
-
从模板块(Pattern space)位置删除行。
-
D
-
删除模板块的第一行。
-
i\
-
在当前行上面插入文本。
-
h
-
拷贝模板块的内容到内存中的缓冲区。
-
H
-
追加模板块的内容到内存中的缓冲区
-
g
-
获得内存缓冲区的内容,并替代当前模板块中的文本。
-
G
-
获得内存缓冲区的内容,并追加到当前模板块文本的后面。
-
l
-
列表不能打印字符的清单。
-
n
-
读取下一个输入行,用下一个命令处理新的行而不是用第一个命令。
-
N
-
追加下一个输入行到模板块后面并在二者间嵌入一个新行,改变当前行号码。
-
p
-
打印模板块的行。
-
P(大写)
-
打印模板块的第一行。
-
q
-
退出Sed。
-
r file
-
从file中读行。
-
t label
-
if分支,从最后一行开始,条件一旦满足或者T,t命令,将导致分支到带有标号的命令处,或者到脚本的末尾。
-
T label
-
错误分支,从最后一行开始,一旦发生错误或者T,t命令,将导致分支到带有标号的命令处,或者到脚本的末尾。
-
w file
-
写并追加模板块到file末尾。
-
W file
-
写并追加模板块的第一行到file末尾。
-
!
-
表示后面的命令对所有没有被选定的行发生作用。
-
s/re/string
-
用string替换正则表达式re。
-
=
-
打印当前行号码。
-
#
-
把注释扩展到下一个换行符以前。
-
以下的是替换标记
-
-
-e command, --expression=command
-
允许多台编辑。
-
-h, --help
-
打印帮助,并显示bug列表的地址。
-
-n, --quiet, --silent
-
取消默认输出。
-
-f, --filer=script-file
-
引导sed脚本文件名。
-
-V, --version
-
打印版本和版权信息。
-
^
-
锚定行的开始 如:/^sed/匹配所有以sed开头的行。
-
$
-
锚定行的结束 如:/sed$/匹配所有以sed结尾的行。
-
.
-
匹配一个非换行符的字符 如:/s.d/匹配s后接一个任意字符,然后是d。
-
*
-
匹配零或多个字符 如:/*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开头的单词的行。
-
\>
-
锚定单词的结束,如/love\>/匹配包含以love结尾的单词的行。
-
x\{m\}
-
重复字符x,m次,如:/0\{5\}/匹配包含5个o的行。
-
x\{m,\}
-
重复字符x,至少m次,如:/o\{5,\}/匹配至少有5个o的行。
-
x\{m,n\}
-
重复字符x,至少m次,不多于n次,如:/o\{5,10\}/匹配5--10个o的行。
-
删除:d命令
-
-
$ sed '2d' example-----删除example文件的第二行。
-
$ sed '2,$d' example-----删除example文件的第二行到末尾所有行。
-
$ sed '$d' example-----删除example文件的最后一行。
-
$ sed '/test/'d example-----删除example文件所有包含test的行。
-
替换:s命令
-
-
$ sed 's/test/mytest/g' example-----在整行范围内把test替换为mytest。如果没有g标记,则只有每行第一个匹配的test被替换成mytest。
-
$ sed -n 's/^test/mytest/p' example-----(-n)选项和p标志一起使用表示只打印那些发生替换的行。也就是说,如果某一行开头的test被替换成mytest,就打印它。
-
$ sed 's/^192.168.0.1/&localhost/' example-----&符号表示替换换字符串中被找到的部份。所有以192.168.0.1开头的行都会被替换成它自已加 localhost,变成192.168.0.1localhost。
-
$ sed -n 's/\(love\)able/\1rs/p' example-----love被标记为1,所有loveable会被替换成lovers,而且替换的行会被打印出来。
-
$ sed 's#10#100#g' example-----不论什么字符,紧跟着s命令的都被认为是新的分隔符,所以,“#”在这里是分隔符,代替了默认的“/”分隔符。表示把所有10替换成100。
-
选定行的范围:逗号
-
-
$ sed -n '/test/,/check/p' example-----所有在模板test和check所确定的范围内的行都被打印。
-
$ sed -n '5,/^test/p' example-----打印从第五行开始到第一个包含以test开始的行之间的所有行。
-
$ sed '/test/,/check/s/$/sed test/' example-----对于模板test和west之间的行,每行的末尾用字符串sed test替换。
-
多点编辑:e命令
-
-
$ sed -e '1,5d' -e 's/test/check/' example-----(-e)选项允许在同一行里执行多条命令。如例子所示,第一条命令删除1至5行,第二条命令用check替换test。命令的执 行顺序对结果有影响。如果两个命令都是替换命令,那么第一个替换命令将影响第二个替换命令的结果。
-
$ sed --expression='s/test/check/' --expression='/love/d' example-----一个比-e更好的命令是--expression。它能给sed表达式赋值。
-
从文件读入:r命令
-
-
写入文件:w命令
-
-
追加命令:a命令
-
-
插入:i命令
-
$ sed '/test/i\\
new line
-------------------------' example
如果test被匹配,则把反斜杠后面的文本插入到匹配行的前面。
-
下一个:n命令
-
-
变形:y命令
-
-
退出:q命令
-
-
保持和获取:h命令和G命令
-
-
保持和互换:h命令和x命令
-
Sed脚本是一个sed的命令清单,启动Sed时以-f选项引导脚本文件名。Sed对于脚本中输入的命令非常挑剔,在命令的末尾不能有任何空白或文本,如果在一行中有多个命令,要用分号分隔。以#开头的行为注释行,且不能跨行。
-
在sed的命令行中引用shell变量时要使用双引号,而不是通常所用的单引号。下面是一个根据name变量的内容来删除named.conf文件中zone段的脚本:
name='zone\ "localhost"'
sed "/$name/,/};/d" named.conf
" named.conf
2011年2月11日 04:18
有用~
2022年8月06日 22:36
Before we show you how you can check CIBIL score, first know that TransUnion CIBIL is an organization and an entity gathers all the consumer’s loan, credit, payment and money related transaction, and this gives a general behavior example and statics allowing to generate a score for each customer also calls as CIBIL score. In simple words, every individual based on their payment choices, credit decisions and money pertains may rank and given CIBIL score points which range up to 900 points. CIBIL score check free In the sense, if the customer receives anything above 750 – 900, then they have high credit affinity. With this the banks and loan facilities may happy to lend credit to them. But in case if the CIBIL score for you is anywhere less than 750 or even worse then there are high chances that you will reject any loans, EMI, or credit requests. Because loan facilities and banks would consider your CIBIL Score as a baseline for approving those requests.
2023年12月12日 23:21
I am incapable of reading articles online very often, but I’m happy I did today. It is very well written, and your points are well-expressed. I request you warmly, please, don’t ever stop writing.Do you want to buy the best Chromebook for artists?
2023年12月17日 13:46
I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.
2023年12月17日 13:48
"This is really wonderful, one-of-a-kind as well as really helpful post, i like it. many thanksHello, I wish for to subscribe for this webpage to take latest updates, so where can i do it please assist Greetings, by utilizing Google I discovered your site even as chasing down a similar subject, your site came up, it looks truly intriguing. I bookmarked it.
"
2023年12月17日 14:41
"This is really wonderful, one-of-a-kind as well as really helpful post, i like it. many thanksHello, I wish for to subscribe for this webpage to take latest updates, so where can i do it please assist Greetings, by utilizing Google I discovered your site even as chasing down a similar subject, your site came up, it looks truly intriguing. I bookmarked it.
"
2023年12月17日 14:42
A to a great degree brilliant blog passage. We are really grateful for your blog passage. fight, law usage You will find an extensive measure of techniques in the wake of heading off to your post. I was absolutely examining for. An obligation of appreciation is all together for such post and please keep it up. Mind blowing work.
2023年12月17日 15:04
"Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.The problem we struggled with was how to provide more assistance
to those in need without the resources to create more bed space."
2023年12月17日 15:18
Very nice blog and articles. I am realy very happy to visit your blog. Now I am found which I actually want. I check your blog everyday and try to learn something from your blog. Thank you and waiting for your new post.Very nice blog and articles. I am realy very happy to visit your blog. Now I am found which I actually want. I check your blog everyday and try to learn something from your blog. Thank you and waiting for your new post.
2023年12月17日 15:30
I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site. I’ve read some good stuff here. Definitely worth bookmarking for revisiting. I surprise how much effort you put to create such a great informative website. Thumbs up guys your doing a really good job.
2023年12月17日 15:35
A to a great degree brilliant blog passage. We are really grateful for your blog passage. fight, law usage You will find an extensive measure of techniques in the wake of heading off to your post. I was absolutely examining for. An obligation of appreciation is all together for such post and please keep it up. Mind blowing work.
2023年12月17日 15:45
It is perfect time to make some plans for the future and it is time to be happy. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!
2023年12月17日 15:55
Succeed! It could be one of the most useful blogs we have ever come across on the subject. Excellent info! I’m also an expert in this topic so I can understand your effort very well. Thanks for the huge help Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day!
2023年12月17日 16:35
Remarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive! You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this...
2023年12月17日 16:40
Remarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive! You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this...
2023年12月17日 16:56
Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info
2023年12月17日 17:02
Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more. i am for the first time here. I found this board and I in finding It truly helpful & it helped me out a lot. I hope to present something back and help others such as you helped me. I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought you have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention
2023年12月17日 17:16
Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info
2023年12月17日 17:17
I really thank you for the gainful data on this wonderful subject and foresee more inconceivable posts. Thankful for getting a charge out of this greatness article with me. I am esteeming everything that much! Envisioning another great article. Favorable circumstances to the maker! All the best!
2023年12月17日 18:36
Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info
2023年12月17日 18:38
Our headquarter is in Philadelphia, PA. We have a global existence, operating in the USA, UK, Asia, and Australia. We are serving our clients all over the globe. Regardless of different time zones, our team manages to facilitate and collaborate with them to deliver high-quality services.
2023年12月17日 18:54
Succeed! It could be one of the most useful blogs we have ever come across on the subject. Excellent info! I’m also an expert in this topic so I can understand your effort very well. Thanks for the huge help Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day!
2023年12月17日 19:15
Good Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free.
2023年12月17日 19:41
I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.
2023年12月17日 19:47
Our headquarter is in Philadelphia, PA. We have a global existence, operating in the USA, UK, Asia, and Australia. We are serving our clients all over the globe. Regardless of different time zones, our team manages to facilitate and collaborate with them to deliver high-quality services.
2023年12月17日 19:49
Our headquarter is in Philadelphia, PA. We have a global existence, operating in the USA, UK, Asia, and Australia. We are serving our clients all over the globe. Regardless of different time zones, our team manages to facilitate and collaborate with them to deliver high-quality services.
2023年12月17日 19:55
"Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.The problem we struggled with was how to provide more assistance
to those in need without the resources to create more bed space."
2023年12月17日 20:10
"Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.The problem we struggled with was how to provide more assistance
to those in need without the resources to create more bed space."
2023年12月17日 20:23
I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site. I’ve read some good stuff here. Definitely worth bookmarking for revisiting. I surprise how much effort you put to create such a great informative website. Thumbs up guys your doing a really good job.
2023年12月17日 20:31
Good Hello! My Name is Hunan I am a professional SEO expert having 4 years . I am specialized in backlinks, creation, off page SEO, website ranking, website taffic, you will come to the right place, Feel free to contact me I see some amazingly important and kept up to length of your strength searching for in your on the site
2023年12月17日 20:37
"I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work… These fortunate web sites are properly ranked by Bing, and by backlinking your site may also position well.
"
2023年12月17日 20:43
Youre so cool! I dont suppose Ive learn something like this before. So good to find somebody with some unique ideas on this subject. realy thank you for beginning this up. this website is something that is needed on the net, somebody with somewhat originality. helpful job for bringing something new to the internet!
2023年12月17日 20:46
It is perfect time to make some plans for the future and it is time to be happy. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!
2023年12月17日 20:55
Remarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive! You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this...
2023年12月17日 21:00
It is perfect time to make some plans for the future and it is time to be happy. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!
2023年12月17日 21:22
I truly welcome this superb post that you have accommodated us. I guarantee this would be valuable for the vast majority of the general population. I am reading your writing well. I know a site that might be helpful for your writing. please read my article and tell us your impressions. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article . This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post . Really i appreciate the effort you made to share the knowledge. The topic here i found was really effective to the topic which i was researching for a long time
2023年12月17日 21:38
"Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.The problem we struggled with was how to provide more assistance
to those in need without the resources to create more bed space."
2023年12月17日 21:59
Youre so cool! I dont suppose Ive learn something like this before. So good to find somebody with some unique ideas on this subject. realy thank you for beginning this up. this website is something that is needed on the net, somebody with somewhat originality. helpful job for bringing something new to the internet!
2023年12月17日 22:12
Best work you have done, this online website is cool with great facts and looks. I have stopped at this blog after viewing the excellent content. I will be back for more qualitative work.Whenever I have some free time, I visit blogs to get some useful info. Today, I found your blog with the help of Google. Believe me; I found it one of the most informative blog.
2024年1月21日 14:30
I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit
2024年1月21日 16:55
EssayTypist is the leading biology dissertation help that is gaining worldwide acclamation due to the ability to deliver top rated critical assessment.
2024年1月21日 17:48
Great webpage brother I am gona inform this to all my friends and contacts
2024年1月21日 18:17
This Post is providing valuable and unique information, I know that you take a time and effort to make a awesome article
2024年1月21日 18:37
Regular visits listed here are the easiest method to appreciate your energy, which is why why I am going to the website everyday, searching for new, interesting info. Many, thank you!
2024年1月21日 19:29
The best article I came across a number of years, write something about it on this pag
2024年1月21日 20:15
Such sites are important because they provide a large dose of useful information
2024年1月21日 21:12
Oh my goodness! an excellent article dude. Thank you However I'm experiencing problem with ur rss. Do not know why Cannot register for it. Could there be any person getting identical rss difficulty? Anybody who knows kindly respond. Thnkx
2024年1月22日 13:55
Impressive web site, Distinguished feedback that I can tackle. Im moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards
2024年1月22日 14:35
I gotta favorite this website it seems very helpful
2024年1月22日 15:08
Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work!
2024年1月22日 15:42
Superb article. Thanks to this blog my expedition has actually ended.
2024年1月22日 16:20
It’s super webpage, I was looking for something like this
2024年1月24日 16:33
Some truly nice and utilitarian info on this internet site , besides I think the layout holds wonderful features
2024年1月24日 18:13
Airport Transport Online is a reliable airport taxi Stansted service provider. For all your airport transfer Stansted services, you should book our professional and reliable services. Our airport transport services are one of the best in Stansted.
2024年1月26日 16:20
바카라사이트 바카라사이트 우리카지노 카지노는 바카라, 블랙잭, 룰렛 및 슬롯 등 다양한 게임을 즐기실 수 있는 공간입니다. 게임에서 승리하면 큰 환호와 함께 많은 당첨금을 받을 수 있고, 패배하면 아쉬움과 실망을 느끼게 됩니다.
2024年1月26日 16:37
하노이 꼭 가봐야 할 베스트 업소 추천 안내 및 예약, 하노이 밤문화 에 대해서 정리해 드립니다. 하노이 가라오케, 하노이 마사지, 하노이 풍선바, 하노이 밤문화를 제대로 즐기시기 바랍니다. 하노이 밤문화 베스트 업소 요약 베스트 업소 추천 및 정리.
2024年1月29日 15:43
No.1 먹튀검증 사이트, 먹튀사이트, 검증사이트, 토토사이트, 안전사이트, 메이저사이트, 안전놀이터 정보를 제공하고 있습니다. 먹튀해방으로 여러분들의 자산을 지켜 드리겠습니다. 먹튀검증 전문 커뮤니티 먹튀클린만 믿으세요!!
2024年1月29日 15:50
베트남 남성전용 커뮤니티❣️ 베트남 하이에나 에서 베트남 밤문화를 추천하여 드립니다. 베트남 가라오케, 베트남 VIP마사지, 베트남 이발관, 베트남 황제투어 남자라면 꼭 한번은 경험 해 봐야할 화끈한 밤문화로 모시겠습니다.
2024年6月03日 18:36
The tech-original mission is to help you better understand technology, and make better decisions in the fields of IT, Tech, and Crypto.
https://www.tech-original.com/
2024年6月08日 12:36
The tech-original mission is to help you better understand technology, and make better decisions in the fields of IT, Tech, and Crypto.
https://www.tech-original.com/