2. Sed 語法初步

sed [-n] [-e] 'command(s)' files 
sed [-n] -f scriptfile files

可以寫在 文件中使用 sed -f scriptfile files 這樣的格式調用

在scriptfile中最後一個命令 寫一行 類似於執行 sed -e 'commad1' -e 'commad2' files 或者 sed 'commad1;commad2' files

這一接使用到的選項有

選項 意義
-n Default printing of pattern buffer 默認情況下會在每行將pattern buffer 的內容打印出來 這個選項抑制打印
-f 執行文件
-e execute執行多個命令

GNU的選項

選項 意思
-n, –quiet, –silent: Same as standard -n option.
-e script, –expression=script: Same as standard -e option.
-f script-file, –file=script-file: Same as standard -f option.
–follow-symlinks: If this option is provided, the SED follows symbolic links while editing files in place. 跟隨鏈接到具體文件
-i[SUFFIX], –in-place[=SUFFIX]: This option is used to edit file in place. If suffix is provided, it takes a backup of the original file, otherwise it overwrites the original file. 這個用來編輯文件 用法 sed -i 'back' 'commad1;command2' files 這個命令的意思是將 files 進行修改 並且 修改之前 會創建一個.back 的備份文件
-l N, –line-lenght=N: This option sets the line length for l command to N characters. 規定每行長度是 N
–posix: This option disables all GNU extensions. 去除掉所有的GNU extensions
-r, –regexp-extended: This option allows to use extended regular expressions rather than basic regular expressions.加強版正則 有的時候會是-E
-u, –unbuffered: When this option is provided, the SED loads minimal amount of data from the input files and flushes the output buffers more often. It is useful for editing the output of “tail -f” when you do not want to wait for the output.
-z, –null-data: By default, the SED separates each line by a new-line character. If NULL-data option is provided, it separates the lines by NULL characters. 使用null 字符 區分行
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章