Langsung ke konten utama

sed (stream editor)

Beberapa cara penggunaan sed.
$ cat port.html
8765
nmap example.com
traceroute example.com
echo "finish"


  1. Menghapus 1 baris sesudah pattern.
    sed -i "/8765/{n;d}" port.html
    $ cat port.html
    8765
    traceroute example.com
    echo "finish"
  2. Menghapus 2 baris sesudah pattern.
    sed -i "/8765/{n;d;d}" port.html
    $ cat port.html
    8765
    echo "finish"
  3. Menghapus 3 baris sesudah pattern.
    sed -i "/8765/{n;d;d;d}" port.html
    $ cat port.html
    8765
  4. Menambahkan baris sesudah pattern
    sed -i "/8765.*/a ping example.com" port.html
    $ cat port.html
    8765
    ping example.com
    nmap example.com
    traceroute example.com
    echo "finish"

Komentar