LINUX sed多行文本如何处理?

嗨部落的朋友们,你们好,今天RAK给大家带来了LINUXsed多行文本的处理方法,大家有不理解的可以下方评论哟。

本案例要求使用sed工具来完成下列任务操作:
修改主机名配置文件
修改hosts文件,添加两条映射记录:192.168.4.5 与 svr5.tarena.com、svr5,还有119.75.217.56与www.baidu.com方案

sed工具的多行文本处理操作:
i:在指定的行之前插入文本
a:在指定的行之后追加文本
c:替换指定的行

步骤
实现此案例需要按照如下步骤进行。
步骤一:修改主机名配置文件

1)确认修改前的配置

[root@svr5 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=svr5.tarena.com

2)使用sed修改主机名配置所在行的内容(c整行替换)

[root@svr5 ~]# sed  -i \
 '/^HOSTNAME/cHOSTNAME=mysvr.tarena.com' /etc/sysconfig/network 

3)确认修改结果

[root@svr5 ~]# cat /etc/sysconfig/network                                             
NETWORKING=yes
HOSTNAME=mysvr.tarena.com

4)恢复原有配置

# sed -i \
‘/^HOSTNAME/cHOSTNAME=svr5.tarena.com’ /etc/sysconfig/network

# cat /etc/sysconfig/network
NETWORKING=yes

步骤二:修改hosts文件,添加新的记录

1)确认修改前的配置

# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

localhost localhost.localdomain localhost6 localhost6.localdomain6

2)使用sed修改hosts文件,添加两行新纪录(a追加)

# sed -i ‘$a192.168.4.5 svr5.tarena.com svr5\

119.75.217.56 www.baidu.com’ /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.4.5 svr5.tarena.com svr5

3)确认修改结果

# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.4.5 svr5.tarena.com svr5

完成以上步骤,我们的问题就解决了,感谢大家的观看,有不同见解评论后会第一时间回复哦!

LINUX sed多行文本如何处理?

此教程来自固定链接:http://www.rakbuluo.com/p41

原文链接:,转发请注明来源!

发表评论

  • 76 Responses to “LINUX sed多行文本如何处理?”
    • Aahk25a

      individual healthcare plans best place to get cialis online
      <a href="https://kamagrajellynow.com">kamagra online</a> Lneqt42
      https://kamagrajellynow.com kamagra oral jelly kaufen deutschland

      回复
    • Uraidssut

      treadmill erectile dysfunction <a href=https://www.withoutbro.com>buy viagra online with prescription</a> erectile dysfunction images of blood vessel
      sildenafil does it work: https://www.withoutbro.com viagra without doctor prescription

      回复
    • Ucjt45o

      viagra levitra cialis comparison best time to take blood pressure meds does medicare cover cialis 2012 <a href="https://tadalafilkiva.com/#">tadalafil</a> - il cialis cura l'eiaculazione precoce https://tadalafilkiva.com/# - cialis beijing what is the penalty for not having health insurance in 2016

      回复
    • canada online pharmacy

      <a href="http://canadianpharmacyhub.com/">legitimate online pharmacies</a>
      http://canadianpharmacyhub.com/
      <a href=http://canadianpharmacyhub.com/>online pharmacy</a>

      回复
    • NDwene

      <a href=http://www.sansordonnancemd.com>viagra online</a> http://www.viagwithoutdr.com

      回复
    • online pharmacies of canada

      <a href="http://canadianpharmacyguru.com/">best canadian online pharmacy</a>
      http://canadianpharmacyguru.com/
      <a href=http://canadianpharmacyguru.com/>canada online pharmacies</a>

      回复
    • overseas pharmacies

      <a href="http://canadianpharmacyhub.com/">mexican online pharmacies</a>
      http://canadianpharmacyhub.com/
      <a href=http://canadianpharmacyhub.com/>canada drugs online reviews</a>

      回复
    • Yamburce

      Reserve the fort down, resolution ya? <a href=https://www.kamagradr.com>kamagra oral jelly at walgreens</a> kamagra shop
      kamagra now co uk contact us: https://www.kamagradr.com kamagra 100mg

      回复
    • canada drugs online reviews

      <a href="http://canadianpharmacyfit.com/">list of safe online pharmacies</a>
      http://canadianpharmacyfit.com/
      <a href=http://canadianpharmacyfit.com/>mexican online pharmacies</a>

      回复
    • most trusted canadian online pharmacies

      <a href="http://canadianpharmacyguru.com/">mail order prescription drugs from canada</a>
      http://canadianpharmacyguru.com/
      <a href=http://canadianpharmacyguru.com/>top rated canadian online pharmacy</a>

      回复
    • mexican online pharmacies

      <a href="http://canadianpharmacycenterhd.com/">safe online pharmacies</a>
      http://canadianpharmacycenterhd.com/
      <a href=http://canadianpharmacycenterhd.com/>online canadian pharmacy</a>

      回复
    • best online canadian pharmacy

      <a href="http://canadianpharmacyfit.com/">certified canadian online pharmacies</a>
      http://canadianpharmacyfit.com/
      <a href=http://canadianpharmacyfit.com/>canadian pharmacies</a>

      回复
    • Yglczpis

      cialis precio farmacia chile kamagra oral jelly
      Egbt61t <a href="https://kamagrajellynow.com">trusted kamagra sites uk</a>
      https://kamagrajellynow.com kamagra

      回复
    • best canadian mail order pharmacies

      <a href="http://canadianpharmacyhub.com/">canada pharmaceuticals online</a>
      http://canadianpharmacyhub.com/
      <a href=http://canadianpharmacyhub.com/>online pharmacy</a>

      回复
    • mexican pharmacies

      <a href="http://canadianpharmaciespreshd.com/">best online international pharmacies</a>
      http://canadianpharmaciespreshd.com/
      <a href=http://canadianpharmaciespreshd.com/>mexican pharmacies online</a>

      回复
    • most trusted canadian online pharmacies

      <a href="http://canadianpharmacycenterhd.com/">online pharmacies of canada</a>
      http://canadianpharmacycenterhd.com/
      <a href=http://canadianpharmacycenterhd.com/>trust online pharmacies</a>

      回复
    • legitimate online pharmacies

      <a href="http://canadianpharmacyguru.com/">overseas pharmacy</a>
      http://canadianpharmacyguru.com/
      <a href=http://canadianpharmacyguru.com/>online pharmacy reviews</a>

      回复
    • overseas pharmacies online

      <a href="http://canadianpharmacieshq.com/">pharmacy in canada</a>
      http://canadianpharmacieshq.com/
      <a href=http://canadianpharmacieshq.com/>mexican border pharmacies</a>

      回复
    • canada drugs

      <a href="http://canadianpharmaciespreshd.com/">reputable canadian pharmacy</a>
      http://canadianpharmaciespreshd.com/
      <a href=http://canadianpharmaciespreshd.com/>safe online pharmacies</a>

      回复
    • canadian mail order pharmacies

      <a href="http://canadianpharmacyfit.com/">canadian drug stores</a>
      http://canadianpharmacyfit.com/
      <a href=http://canadianpharmacyfit.com/>most reliable canadian pharmacies</a>

      回复
    • canadian pharcharmy online

      <a href="http://canadianpharmacieshq.com/">mexican pharmacy</a>
      http://canadianpharmacieshq.com/
      <a href=http://canadianpharmacieshq.com/>top 10 online pharmacies</a>

      回复
    • legitimate canadian mail order pharmacies

      <a href="http://canadianpharmacycenterhd.com/">overseas pharmacy</a>
      http://canadianpharmacycenterhd.com/
      <a href=http://canadianpharmacycenterhd.com/>canadian internet pharmacy</a>

      回复
    • list of safe online pharmacies

      <a href="http://canadianpharmaciesdepot.com/">overseas online pharmacy</a>
      http://canadianpharmaciesdepot.com/
      <a href=http://canadianpharmaciesdepot.com/>mexican online pharmacies</a>

      回复
    • best online pharmacies

      <a href="http://canadianpharmaciespreshd.com/">list of legitimate canadian pharmacies</a>
      http://canadianpharmaciespreshd.com/
      <a href=http://canadianpharmaciespreshd.com/>online canadian pharmacy</a>

      回复
    • reliable mexican pharmacies

      <a href="http://canadianpharmaciesdepot.com/">best canadian online pharmacy</a>
      http://canadianpharmaciesdepot.com/
      <a href=http://canadianpharmaciesdepot.com/>best canadian pharmacies</a>

      回复
    • reputable online pharmacy

      <a href="http://canadianfastpharmacy.com/">canadian pharmacy</a>
      http://canadianfastpharmacy.com/
      <a href=http://canadianfastpharmacy.com/>canadian online pharmacies ratings</a>

      回复
    • canadian pharcharmy online

      <a href="http://canadianpharmacieshq.com/">canada pharmacies online</a>
      http://canadianpharmacieshq.com/
      <a href=http://canadianpharmacieshq.com/>international pharmacy</a>

      回复
    • canada pharmacy

      <a href="http://canadianfastpharmacy.com/">canada drugs online</a>
      http://canadianfastpharmacy.com/
      <a href=http://canadianfastpharmacy.com/>canada pharmacy</a>

      回复
    • pharmacy drugstore online

      <a href="http://canadianpharmacynethd.com/">mexican online pharmacies</a>
      http://canadianpharmacynethd.com/
      <a href=http://canadianpharmacynethd.com/>reputable mexican pharmacies online</a>

      回复
    • canada online pharmacy

      <a href="http://canadianpharmaciesdepot.com/">aarp recommended canadian pharmacies</a>
      http://canadianpharmaciesdepot.com/
      <a href=http://canadianpharmaciesdepot.com/>canada pharmaceuticals online</a>

      回复
    • Aamburce

      Beneficial knowledge. Appreciate it. <a href=https://www.kamagradr.com>kamagra oral jelly at walgreens</a> home pharma kamagra
      kamagra oral gel uk: https://www.kamagradr.com kamagra sale

      回复
    • best online international pharmacies

      <a href="http://canadianpharmacynethd.com/">canadian online pharmacy no prescription</a>
      http://canadianpharmacynethd.com/
      <a href=http://canadianpharmacynethd.com/>online pharmacies</a>

      回复
    • trust online pharmacies

      <a href="http://canadiannextpharmacy.com/">canadian online pharmacy</a>
      http://canadiannextpharmacy.com/
      <a href=http://canadiannextpharmacy.com/>mexican pharmacies</a>

      回复
    • canadian pharmacies without an rx

      <a href="http://canadianfastpharmacy.com/">list of reputable canadian pharmacies</a>
      http://canadianfastpharmacy.com/
      <a href=http://canadianfastpharmacy.com/>canadian pharmacies mail order</a>

      回复
    • aarp recommended canadian pharmacies

      <a href="http://canadianpharmacynethd.com/">canada drugs online review</a>
      http://canadianpharmacynethd.com/
      <a href=http://canadianpharmacynethd.com/>legitimate canadian pharmacies online</a>

      回复
    • reliable canadian pharmacy

      <a href="http://canadiannextpharmacy.com/">my canadian pharmacy</a>
      http://canadiannextpharmacy.com/
      <a href=http://canadiannextpharmacy.com/>reputable canadian online pharmacies</a>

      回复
    • safe canadian internet pharmacies

      <a href="http://canadianpharmacieselite.com/">online pharmacies canada</a>
      http://canadianpharmacieselite.com/
      <a href=http://canadianpharmacieselite.com/>overseas pharmacies online</a>

      回复
    • overseas pharmacy

      <a href="http://canadiannextpharmacy.com/">canadian drugs</a>
      http://canadiannextpharmacy.com/
      <a href=http://canadiannextpharmacy.com/>online pharmacies canada</a>

      回复
    • canadian pharmaceuticals online reviews

      <a href="http://canadianpharmacieselite.com/">best canadian mail order pharmacies</a>
      http://canadianpharmacieselite.com/
      <a href=http://canadianpharmacieselite.com/>canadian pharmacies shipping to usa</a>

      回复
    • mexican pharmacies shipping to usa

      <a href="http://canadianonlinepharmacynote.com/">canadian pharmacies that ship to us</a>
      http://canadianonlinepharmacynote.com/
      <a href=http://canadianonlinepharmacynote.com/>mexican pharmacies online</a>

      回复
    • reputable canadian online pharmacies

      <a href="http://canadianpharmacieselite.com/">aarp approved canadian online pharmacies</a>
      http://canadianpharmacieselite.com/
      <a href=http://canadianpharmacieselite.com/>aarp recommended canadian pharmacies</a>

      回复
    • best canadian pharcharmy online

      <a href="http://canadianonlinepharmacynote.com/">mexican border pharmacies</a>
      http://canadianonlinepharmacynote.com/
      <a href=http://canadianonlinepharmacynote.com/>canadian pharmaceuticals online safe</a>

      回复
    • legitimate canadian pharmacies online

      <a href="http://canadianonlinepharmacynote.com/">canadian pharmaceuticals online safe</a>
      http://canadianonlinepharmacynote.com/
      <a href=http://canadianonlinepharmacynote.com/>international pharmacy</a>

      回复
    • best canadian pharmacies

      <a href="http://canadianpharmacyhopemeds.com/">best canadian mail order pharmacies</a>
      http://canadianpharmacyhopemeds.com/
      <a href=http://canadianpharmacyhopemeds.com/>canada drug</a>

      回复
    • canadian online pharmacy reviews

      <a href="http://canadianpharmacyhopemeds.com/">legitimate canadian pharmacy</a>
      http://canadianpharmacyhopemeds.com/
      <a href=http://canadianpharmacyhopemeds.com/>canadian trust pharmacy</a>

      回复
    • best canadian mail order pharmacies

      <a href="http://canadianonlinepharmacykkr.com/">best 10 online canadian pharmacies</a>
      http://canadianonlinepharmacykkr.com/
      <a href=http://canadianonlinepharmacykkr.com/>drugstore online</a>

      回复
    • canadian pharmacies shipping to usa

      <a href="http://canadianonlinepharmacykkr.com/">top rated canadian pharmacies online</a>
      http://canadianonlinepharmacykkr.com/
      <a href=http://canadianonlinepharmacykkr.com/>my canadian pharmacy</a>

      回复
    • online pharmacies canada

      <a href="http://canadianonlinepharmacykkr.com/">reliable canadian pharmacy</a>
      http://canadianonlinepharmacykkr.com/
      <a href=http://canadianonlinepharmacykkr.com/>list of legitimate canadian pharmacies</a>

      回复
    • international pharmacy

      <a href="http://canadianbestpharmacyonline.com/">canadian pharcharmy online</a>
      http://canadianbestpharmacyonline.com/
      <a href=http://canadianbestpharmacyonline.com/>canadian pharmacies shipping to usa</a>

      回复
    • mexican border pharmacies shipping to usa

      <a href="http://canadianbestpharmacyonline.com/">top canadian pharmacies</a>
      http://canadianbestpharmacyonline.com/
      <a href=http://canadianbestpharmacyonline.com/>aarp approved canadian online pharmacies</a>

      回复
    • online pharmacies legitimate

      <a href="http://canadianbestpharmacyonline.com/">canadian pharmacy online</a>
      http://canadianbestpharmacyonline.com/
      <a href=http://canadianbestpharmacyonline.com/>mexican border pharmacies</a>

      回复
    • cialis side effects

      sudden hair loss permanent hair loss
      https://cialisgrade.com brand cialis buy
      <a href="https://cialisgrade.com">cialis daily</a>

      回复
    • highest rated canadian pharmacies

      <a href="http://canadianpharmacyhub.com/">reputable canadian pharmacy</a>
      http://canadianpharmacyhub.com/
      <a href=http://canadianpharmacyhub.com/>canada drugs</a>

      回复
    • pharmacy online

      <a href="http://canadianpharmacyhub.com/">best mexican online pharmacies</a>
      http://canadianpharmacyhub.com/
      <a href=http://canadianpharmacyhub.com/>list of reputable canadian pharmacies</a>

      回复
    • most trusted canadian pharmacy

      <a href="http://canadianpharmacyguru.com/">online pharmacy canada</a>
      http://canadianpharmacyguru.com/
      <a href=http://canadianpharmacyguru.com/>canadian mail order pharmacies</a>

      回复
    • canada pharmacy

      <a href="http://canadianpharmacyguru.com/">canadian pharcharmy online</a>
      http://canadianpharmacyguru.com/
      <a href=http://canadianpharmacyguru.com/>canada drug</a>

      回复
    • canadian pharmacies mail order

      <a href="http://canadianpharmacyfit.com/">legitimate canadian pharmacy online</a>
      http://canadianpharmacyfit.com/
      <a href=http://canadianpharmacyfit.com/>best online international pharmacies</a>

      回复
    • reliable mexican pharmacies

      <a href="http://canadianpharmacyfit.com/">canada pharmacies online prescriptions</a>
      http://canadianpharmacyfit.com/
      <a href=http://canadianpharmacyfit.com/>top canadian pharmacies</a>

      回复
    • mexican pharmacies online

      <a href="http://canadianpharmaciespreshd.com/">top canadian pharmacies</a>
      http://canadianpharmaciespreshd.com/
      <a href=http://canadianpharmaciespreshd.com/>canadian pharmacies without an rx</a>

      回复
    • canada pharmacy online

      <a href="http://canadianpharmacycenterhd.com/">best canadian online pharmacies</a>
      http://canadianpharmacycenterhd.com/
      <a href=http://canadianpharmacycenterhd.com/>legitimate canadian mail order pharmacies</a>

      回复
    • mexican online pharmacies

      <a href="http://canadianpharmacycenterhd.com/">mexican online pharmacy</a>
      http://canadianpharmacycenterhd.com/
      <a href=http://canadianpharmacycenterhd.com/>reputable online pharmacy</a>

      回复
    • EExcuppy

      show blood pressure machines - <a href="https://www.withoutbro.com">viagra online</a> Ovsp34b
      cialis et taux de psa
      gmail sent items viagra: <a href="https://www.withoutbro.com/">is it better to take viagra on an empty stomach</a>

      回复
    • reputable mexican pharmacies online

      <a href="http://canadianpharmaciespreshd.com/">top rated canadian pharmacies online</a>
      http://canadianpharmaciespreshd.com/
      [url=http://canadianpharmaciespreshd.com/]list of safe online pharmacies[/url]

      回复
    • top rated canadian pharmacies online

      <a href="http://canadianpharmacieshq.com/">legitimate canadian mail order pharmacies</a>
      http://canadianpharmacieshq.com/
      <a href=http://canadianpharmacieshq.com/>list of approved canadian pharmacies</a>

      回复
    • top canadian pharmacies

      <a href="http://canadianpharmaciespreshd.com/">canadian pharmacies</a>
      http://canadianpharmaciespreshd.com/
      <a href=http://canadianpharmaciespreshd.com/>canadian pharmaceuticals online reviews</a>

      回复
    • best online pharmacy

      <a href="http://canadianpharmacieshq.com/">canadian online pharmacies ratings</a>
      http://canadianpharmacieshq.com/
      <a href=http://canadianpharmacieshq.com/>online pharmacies legitimate</a>

      回复
    • discount canadian drugs

      <a href="http://canadianpharmaciesdepot.com/">canadian pharcharmy online</a>
      http://canadianpharmaciesdepot.com/
      <a href=http://canadianpharmaciesdepot.com/>mexican online pharmacies</a>

      回复
    • best online pharmacy

      <a href="http://canadianpharmaciesdepot.com/">trust online pharmacies</a>
      http://canadianpharmaciesdepot.com/
      <a href=http://canadianpharmaciesdepot.com/>canadian mail order pharmacies</a>

      回复
    • mexican pharmacies shipping to usa

      <a href="http://canadianfastpharmacy.com/">safe online pharmacies</a>
      http://canadianfastpharmacy.com/
      <a href=http://canadianfastpharmacy.com/>canadian pharmacies online reviews</a>

      回复
    • list of legitimate canadian pharmacies

      <a href="http://canadianpharmacieshq.com/">canadian pharmacies without an rx</a>
      http://canadianpharmacieshq.com/
      <a href=http://canadianpharmacieshq.com/>overseas pharmacies shipping to usa</a>

      回复
    • CharlesHob

      tinder date , how to use tinder
      <a href=http://tinderdatingsiteus.com/?>tinder login</a>

      回复
    • Tinder dating site

      browse tinder for free , tinder login
      <a href=http://tinderdatingsiteus.com/?>tindr </a>

      回复
    • tinder site

      how to use tinder , tinder login

      回复
    • Stephenpeaky

      viagra without a doctor prescription usa <a href=" http://sild100fast.com/# ">cheap generic viagra</a> buy generic 100mg viagra online

      回复
    • aarp recommended canadian pharmacies

      <a href="http://canadianpharmacynethd.com/">certified canadian online pharmacies</a>
      http://canadianpharmacynethd.com/
      <a href=http://canadianpharmacynethd.com/>canadian drug stores</a>

      回复
    • 20190618 PING 通告 : 高防服务器的含义和它的作用是啥?