1. What is sed?
1) stream editor
(1) input --(edited)--> output
2. Essential command
1) s : substitution
(1) 4 parts of command
a. s : command
b. /../../ : delimiter
c. ^fjdkal : regular expression pattern search pattern
d. fdjj : replacement string
(2) Use '/' as a delimiter
a. '\' : sed 's\/user\/local\/bin/common\/bin' <old >new
b. '_' : sed 's_/user_/local_/bin_/common_/bin' <old >new
c. ':' : sed 's:/user:/local:/bin/common:/bin' <old >new
d. '|' : sed 's|/user/local/bin|common/bin' <old > new
(3) Use '&' as matched string
a. add parenthesis to a pattern : sed 's/abc/(&)/' <old <new
- '&' means pattern, in this command, "abc"
2) '-e' command
(1) Combines multiple commands into a single process.
3) Substitute flags
(1) /g : global replacement, as in vi
3. Others
1) File names
(1) any argument that doesn't start with sed option, it is the file name.
2) -f : use sed command file
(1) sed -f sedcommands <old >new
3) '\' : to divide sed command into multiple lines.
4) Bourne shall(bash) quote : using ' to quote commands in multiple lines.
5) Restricting to a line number
(1) by number : sed '3 s/[0-9][0-9]*//' <old <new
a. remove the first number in the 3rd line.
(2) by pattern : sed '/^#/ s/[0-9][0-9]*//' <old <new
a. remove the first number which is starting with '#'.
댓글 없음:
댓글 쓰기