TODO…
sed – stream editor for filtering and transforming text
# man sed
NAME
sed – stream editor for filtering and transforming text
SYNOPSIS
sed [OPTION]… {script-only-if-no-other-script} [input-file]…
DESCRIPTION
Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a
pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over
the input(s), and is consequently more efficient. But it is sed’s ability to filter text in a pipeline which particularly distin-
guishes it from other types of editors.
-n, –quiet, –silent
suppress automatic printing of pattern space
-e script, –expression=script
add the script to the commands to be executed
-f script-file, –file=script-file
add the contents of script-file to the commands to be executed
-i[SUFFIX], –in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
-l N, –line-length=N
specify the desired line-wrap length for the `l’ command
–posix
disable all GNU extensions.
-r, –regexp-extended
use extended regular expressions in the script.
-s, –separate
consider files as separate rather than as a single continuous long stream.
….
.
.
address อาจจะเป็น หมายเลขบรรทัด หรือ regex
command คือ คำสั่งของ sed
ถ้าใช้หลายๆคำสั่ง จะใส่คำสั่งไว้ใน { } และ แยกแต่ละคำสั่งโดยใช้ ;
.
Examples
# sed ‘/^#/d’ /etc/squid/squid.conf
# sed ‘s/pattern/word/g’ mytextfile
# sed “s/UUID[^ ]*/UUID=`vol_id /dev/sda6|grep ID_FS_UUID_ENC|awk -F= ‘{print $2}’`/g” /boot/grub/menu.lst
.
More Info
number #1 page in Google on ‘sed’! Sed – An Introduction and Tutorial