




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1/1sed详细用法(sed详细用法)sed详细用法(sed详细用法)Seddetailedusageintroduction1.briefintroductionofSedSedisanonlineeditorthathandlesonelineofcontentatatime.Whenthecurrentprocessingrowsarestoredinatemporarybuffer,calledmodelspace(patternspace),thenthecontentsofthebufferusingtheSEDcommand,afterprocessing,thecontentsofthebuffertothescreen.Next,youprocessthenextline,soitrepeatsuntiltheendofthefile.Thefilecontenthasnotchangedunlessyouusetheredirectionstorageoutput.Sedisprimarilyusedtoautomaticallyeditoneormorefiles;tosimplifytherepeatedoperationofthedocument;towriteconversionprogramsandsoon.ThefollowingistheGnuversionofSed3.02.2.addressingYoucanlocatethelinesyouwanttoeditbyaddressing,whichismadeupofnumbers,andthenumberofrowsseparatedbycommasindicatestherangeofthelinesinwhichthetwoactsstart(includingthetwolinesrepresentedbythenumberofrows)(twolines).If1,3means1,2,and3lines,thedollarsign($)representsthelastline.Rangecanbedeterminedbymeansofdata,regularexpressions,ortwocombinations.3.SedcommandTherearetwoformsofcallingtheSEDcommand:Sed,[options],’command’,file(s)Sed,[options],-f,scriptfile,file(s)A\Addsasinglelineoftextattheendofthecurrentrow.BlableBranchintothescriptwithtags,andifthebranchdoesnotexist,branchtotheendofthescript.C\Changethetextofthebankwithnewtext.DRemovesrowsfromthetemplateblock(Pattern,space)location.DDeletethefirstlineofthetemplateblock.I\Insertstextabovethecurrentline.HCopythecontentsofthetemplateblockintothememorybuffer.HAppendthecontentofthetemplateblocktothememorybufferGGetsthecontentsofthememorybufferandreplacesthetextinthecurrenttemplateblock.GGetsthecontentsofthememorybufferandappendsittothetextofthecurrenttemplateblock.LListofcharactersthatcannotprintcharacters.NReadsthenextinputlineandprocessesthenewlinewiththenextcommand,notthefirstcommand.NAppendthenextinputlinetothetemplateblockandinsertanewlinebetweenthetwotochangethecurrentrownumber.PPrintlinesoftemplateblocks.P(uppercase)Printthefirstlineoftemplateblocks.QExitSed.RfileReadlinefromfile.TlabelTheifbranchstartsfromthelastline,andoncetheconditionismet,ortheT,tcommand,itwillleadtobranchingtothelabeledcommand,ortotheendofthescript.TlabelTheerrorbranchstartswiththelastline,andifanerroroccurs,ortheT,thetcommandcausesthebranchtogotothelabeledcommand,ortotheendofthescript.WfileWriteandappendthetemplateblocktotheendofthefile.WfileWriteandappendthefirstlineofthetemplateblocktotheendofthefile.!Indicatesthatthefollowingcommandtakeseffectonalltherowsthathavenotbeenselected.S/re/stringReplaceregularexpressionstringwithre.=Printcurrentlinenumber.#Extendthecommenttothenextlinebreak.ThefollowingisthereplacementtokenGindicatesinlinefullsubstitution.Prepresentstheprintline.Wmeanstowriterowstoafile.TheXrepresentsthetextintheswapblockandthetextinthebuffer.Ymeanstranslatingacharacterintoanothercharacter(butnotregularexpressions)4.option-e,command,--expression=commandAllowmultipleedits.-h,--helpPrinthelpanddisplaytheaddressofthebuglist.-n,--quiet,--thsed.$Theendoftheanchorline,suchas:/sed$/matchesallrowsendingwithsed..Acharacterthatmatchesanewlinecharacter,suchas:/s.d/,matchess,followedbyanarbitrarycharacter,followedbyD.*Matcheszeroormoresearchcharacterstoreplaceothercharacters,suchass/love/****/,love,andthisis**love**.\Anchorthebeginningofaword,suchas:/\love/matchesthelinecontainingthewordatthebeginningofthelove.\Anchortheendofaword,suchas/love\/,thatmatchesthelinecontainingthewordendinginlove.X\{m\}Repeatcharactersx,mtimes,suchas:/0\{5\}/matchingcontains5orows.X\{m,\}Repeatcharacterx,atleastmtimes,suchas:/o\{5,\}/,thereareatleast5olines.X\{m,n\}Repeatcharacterx,atleastmtimes,nomorethanntimes,forexample:/o\{5,10\}/matches5--10orows.6.exampleDelete:Dcommand$sed’2d’exampledeletesthesecondlineoftheexamplefile.$sed,’2,$d’,example,deletethesecondlineoftheexamplefiletoallrowsattheend.$sed’$d’exampledeletesthelastlineoftheexamplefile.$sed,’/test/’d,example,deletetheexamplefile,allrowscontainingtest.Replace:scommandThe$sed’s/test/mytest/g’examplereplacesthetestwithmytestthroughouttheentirerow.IfthereisnoGtag,onlythefirstmatchingtestofeachrowisreplacedwithmytest.The$sed-n’s/ est/mytest/p’example(-n)optionisusedwiththePflagtoindicatethatonlythereplacementrowshavebeenprinted.Thatis,ifaline’sinitialtestisreplacedwithmytest,printit.The$sed,’s/?.168.0.1/localhost/’,andexamplesymbolsrepresentthepartsfoundinthereplacementstring.Allrowsbeginningwith192.168.0.1willbereplacedbyaddinglocalhosttoitselfandbecoming192.168.0.1localhost.The$sed-n’s/\(love\)able/\1rs/p’exampleloveismarked1,andalltheloveablewillbereplacedwithlovers,andthereplacementlinewillbeprintedout.Nomatterwhat$sed’s#10#100#g’examplecharacter,followedbythescommandareconsideredtobethenewseparator,so,#hereisadelimiter,insteadofthedefault/separator.Meansreplacingall10to100.Selectedrangeoflines:comma$sed,-n,’/test/,/check/p’,example,alllineswithintherangeidentifiedbytemplatestestandcheckareprinted.$sed,-n,’5,/ est/p’,example,printstartsfromthefifthlinetothefirstrowthatcontainstherowsthatstartwithtest.$sed,’/test/,/check/s/$/sed,test/’,example,rowsbetweentemplatestestandWest,replacedbystringsedtestattheendofeachline.Multiedit:ecommand-e’1,5d’-e’s/test/check/’example$sed(-e)inthesamerowoptionallowstheexecutionofmultipleorders.Asshownintheexample,thefirstcommanddeleteslines1through5,andthesecondcommandreplacestestwithcheck.Theorderinwhichthecommandisexecutedhasconsequencesfortheresults.Ifthetwocommandsarereplacementcommands,thefirstreplacementcommandwillaffecttheresultsofthesecondreplacementcommands.A$sed,--expression=‘s/test/check/’,--expression=‘/love/d’,example,abettercommandthan-eis--expression.Itcanassignvaluestosedexpressions.Readfromfile:Rcommand$sed’/test/rfile’intheexamplefileofthecontentisdisplayedatthebackandreadintest,ifthematchingline,multiline,filecontentwillbeshownbelowallmatchingrowsof.Writefile:Wcommand$sed,-n,’/test/w,file’,exampleinexample,alllinescontainingtestarewrittentofile.Appendcommand:acommandThe$sed,’/ est/a\\this,is,a,example’,example’this,is,a,example’,andaareappendedtothelineatthebeginningofthetest,andsedrequiresabackslashfollowedbythecommand.Insert:Icommand$sed’/test/i\\Newline’exampleIftestismatched,insertthetextbehindthebackslashtothefrontofthematchingline.Next:ncommand$sed’/test/{n;s/aa/bb/example;}’iftestismatching,movetothenextline,theline,replacethelineAAintoBB,andprinttheline,andthencontinueto.Deform:ycommandThe$sed’1,10y/abcde/ABCDE/’examplechangesalltheABCDEinthe1--10linetouppercase.Notethattheregularexpressionmetacharactercannotusethiscommand.Exit:QcommandAfter$tenth,’10q’,example,printouttheSEDline,exitsed.Keepandget:HcommandandGcommand-e’/test/h’-e’$Gexample$sedinseddocumentprocessing,eachrowisstoredinatemporarybuffercalledmodespace,unlesstherowisdeletedoroutputiscancelled,otherwiseallprocessedrowswillbeprintedonthescreen.Next,themodespaceisemptiedandstoredinanewlinewaitingforprocessing.Inthisexample,whenthelinethatmatchestestisfound,itisstoredinthepatternspace,andtheHcommandcopiesitandstoresitintoaspecialbuffercalledth
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025届山东省菏泽市高三10月期中考-政治试题(含答案)
- 中医专长培训定制班一学员协议书
- 2024年河北省中等职业对口升学中职英语真题(解析版)
- 2025年泰安货运从业资格证试题及答案
- 脊柱外科相关知识
- 2025年份第二季度职业柔道俱乐部寝技专家训练器械维护协议
- 工程售后服务协议书
- 股权转让附条件协议
- 二零二五版房屋合租协议
- 建设加油加气加氢充电一体站项目可行性研究报告写作模板-拿地申报
- 2023学年杭州市余杭区七年级语文下学期期中考试卷附答案解析
- 9《小水滴的诉说》(教学设计)-2023-2024学年统编版道德与法治二年级下册
- 2025年安徽合肥兴泰金融控股集团招聘笔试参考题库含答案解析
- 《道路交通安全法》课件完整版
- 加快形成农业新质生产力
- 施工现场应急救援知识
- 饲料行业业务员聘用合同范本
- 全国园地、林地、草地分等定级数据库规范1123
- 人工智能在教学动画设计中的应用与创新路径探究
- 护理中医新技术新项目
- VDA-6.3-2016过程审核检查表
评论
0/150
提交评论