一条sed命令的疑问

5:02:00 PM 0 Comments

one.txt的内容为

one
two
three

执行
sed -e '1c eky' -e 'w two.txt' one.txt

two.txt的内容变成


为什么不是

eky
two
three



因为你使用的是c命令。
c文本"eky"不会放到pattern space里面。

sed '1s/.*/eky/;w two.txt'



`c\'
`TEXT'
Delete the lines matching the address or address-range, and output
the lines of text which follow this command (each but the last
ending with a `\', which are removed from the output) in place of
the last line (or in place of each line, if no addresses were
specified). A new cycle is started after this command is done,
since the pattern space will have been deleted.


Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard.