課程
/運(yùn)維&測試
/Linux
/shell編程之正則表達(dá)式
sed -ni '3s/60/99/g' student.txt
2016-01-03
源自:shell編程之正則表達(dá)式 2-5
正在回答
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命令有一個緩沖區(qū),-n選項(xiàng)把緩沖區(qū)的內(nèi)容輸出到屏幕,之后緩沖區(qū)就被清空了,再執(zhí)行-i就只剩下空的內(nèi)容,寫入到文件里文件內(nèi)容就沒了
加上 -i 參數(shù)后 表示 將修改的內(nèi)容同步到文件中,這時本身就不會顯示啊
手動指定-n 也是沒有效果的
舉報
為你帶來shell編程中的正則表達(dá)式,能夠熟練運(yùn)用正則表達(dá)式
1 回答文本內(nèi)刪除內(nèi)容的快捷鍵?
1 回答awk中$0是代表每一行的內(nèi)容吧?
1 回答sed命令不加-n
1 回答正則中括號內(nèi)的取反問題,空行為什么不會列出
1 回答sort命令后面的條件判斷不加引號也可以執(zhí)行?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-10-19
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.
2016-04-21
我的理解:sed命令有一個緩沖區(qū),-n選項(xiàng)把緩沖區(qū)的內(nèi)容輸出到屏幕,之后緩沖區(qū)就被清空了,再執(zhí)行-i就只剩下空的內(nèi)容,寫入到文件里文件內(nèi)容就沒了
2016-01-04
加上 -i 參數(shù)后 表示 將修改的內(nèi)容同步到文件中,這時本身就不會顯示啊
手動指定-n 也是沒有效果的