好好学习天天向上77
2016-01-03 21:39
sed -ni '3s/60/99/g' student.txt
info sed =>
`-n'
`--quiet'
`--silent'
By default, `sed' prints out the pattern space at the end of each
cycle through the script (*note How `sed' works: Execution Cycle.).
These options disable this automatic printing, and `sed' only
produces output when explicitly told to via the `p' command.
`-i[SUFFIX]'
`--in-place[=SUFFIX]'
This option specifies that files are to be edited in-place. GNU
`sed' does this by creating a temporary file and sending output to
this file rather than to the standard output.(1).
This option implies `-s'.
When the end of the file is reached, the temporary file is renamed
to the output file's original name. The extension, if supplied,
is used to modify the name of the old file before renaming the
temporary file, thereby making a backup copy(2)).
This rule is followed: if the extension doesn't contain a `*',
then it is appended to the end of the current filename as a
suffix; if the extension does contain one or more `*' characters,
then _each_ asterisk is replaced with the current filename. This
allows you to add a prefix to the backup file, instead of (or in
addition to) a suffix, or even to place backup copies of the
original files into another directory (provided the directory
already exists).
If no extension is supplied, the original file is overwritten
without making a backup.
我的理解:sed命令有一个缓冲区,-n选项把缓冲区的内容输出到屏幕,之后缓冲区就被清空了,再执行-i就只剩下空的内容,写入到文件里文件内容就没了
加上 -i 参数后 表示 将修改的内容同步到文件中,这时本身就不会显示啊
手动指定-n 也是没有效果的
shell编程之正则表达式
39682 学习 · 73 问题
相似问题