zoukankan      html  css  js  c++  java
  • sed 指令

    sed -e 's/:/ /g'  

    将待处理文本行中:替换为空格,

    s/A/B/g 是sed中的替换命令,

    将A替换为B,

    其中,A可以是正则表达式.

    g表示全部替换.

     

    sed 指令

    直接取代 -2008/04/21
    sed 3cxxx file 只是會顯示結果是如何給你看

    如果這麼作 sed -i 3cxxx file,file 裡的第三行馬上會被更改

    在 file裡的第三行後面加入一行xxx
    sed 3axxx file

    在 file裡的第三行前面加入一行xxx
    sed 3ixxx file

    將 file裡的第三行修改為 xxx
    sed 3cxxx file

    將 file裡的 old-string改為 new-string
    sed s/old-string/new-string/g file

    ref: http://phorum.study-area.org/viewtopic.php?p=223722#223722

    將 zone.ssorc.tw檔案裡面的某一行是 "IN A"的全部字元,改成 "IN A 10.1.1.123"
    sed -i "s/IN A.*/IN A 10.1.1.123/g" zone.ssorc.tw

    如果是 perl

    perl -pi -e 's/IN A.*/IN A 10.1.1.123/g' zone.ssorc.tw

    取括號裡面的值
    more test.txt

    (aaa)
    (bbb)
    (ccc)

    cat test.txt | sed 's/((.*))/1/'

    圖 sed-1.jpg

    aaa
    bbb
    ccc

       如果是有中括號的話
          test.txt

    (aaa)
    [bbb]
    (ccc)

    cat test.txt | sed -e 's/((.*))/1/' -e 's/[(.*)]/1/'

    圖 sed-2.jpg

    aaa
    bbb
    ccc

    取某字串後的值
    a="123 aaa bbb ccc"
    echo $a | sed 's/^[0-9]{1,10}//'

    另一種玩法
    echo $a | sed 's/.*123//'

    取某行到某行之間
       file.txt內容為

    111111111111
    222222222222
    333333333333
    444444444444
    555555555555
    666666666666
    777777777777
    888888888888
    999999999999
    000000000000

       作法: 取當中字串333與888之間的值
          cat file.txt | sed -ne '/33333/,/88888/p'

    ref:
    http://linux.tnc.edu.tw/techdoc/shell/x737.html
    http://phi.sinica.edu.tw/aspac/reports/96/96005/

    特殊符號
    vi txt1.txt

    xxx^@

    file txt1.txt 為 ASCII text, with no line terminators

    使用 sed -e 'l' 得知其 ASCII 碼
    [root@test bin]# sed -e 'l' 321
    xxx00$
    xxx[root@test bin]#

    可行作法一
    sed -e 's/.*/& /' txt1.txt | awk '{print $1}' > txt2.txt

    作法二
    tr -d "00$" < txt1.txt > txt2.txt

    作法三
    tr -s "[00]" "[ ]" < txt1.txt  > txt2.txt

    圖 tr.jpg

  • 相关阅读:
    压缩流GZipStream
    委托和事件
    .NET垃圾回收机制
    程序集相关知识
    生活
    poj 3767 I Wanna Go Home
    fw:Python GUI的设计工具
    How to configure an NTP client and server on CentOS/RedHat
    FW:Tripwire
    Bash if 判断 集合
  • 原文地址:https://www.cnblogs.com/the-tops/p/5581000.html
Copyright © 2011-2022 走看看