Stream editor for filtering text用于过滤文本的流编辑器
sed stands for "stream editor". It performs text transformations on an input stream (a file or pipe). Unlike interactive editors, sed is non-interactive and perfect for automated text processing, search-and-replace operations, and complex text manipulations.
sed代表"stream editor"(流编辑器)。它对输入流(文件或管道)执行文本转换。与交互式编辑器不同,sed是非交互式的,非常适合自动化文本处理、搜索和替换操作以及复杂的文本操作。
| Option选项 | Full Name完整名称 | Description描述 | Example示例 |
|---|---|---|---|
-i |
in-place就地编辑 | Edit files in place就地编辑文件 | sed -i 's/foo/bar/g' file.txt |
-n |
quiet安静模式 | Suppress automatic printing抑制自动打印 | sed -n '5p' file.txt |
-e |
expression表达式 | Add script to commands将脚本添加到命令 | sed -e 's/a/b/' -e 's/c/d/' |
-f |
file文件 | Add script from file从文件添加脚本 | sed -f script.sed file.txt |
| Command命令 | Description描述 | Example示例 |
|---|---|---|
s/pattern/replacement/ |
Substitute替换 | sed 's/foo/bar/' |
/pattern/d |
Delete matching lines删除匹配的行 | sed '/error/d' |
Nd |
Delete Nth line删除第N行 | sed '5d' |
Np |
Print Nth line打印第N行 | sed -n '5p' |
s/.*$// |
Delete to end of line删除到行尾 | sed 's/.*$//' file.txt |
🌊 "sed" = stream editor - Edit text as it flows by!
🌊 "sed" = stream editor(流编辑器) - 在文本流动时编辑!
🔄 s/old/new/ = substitute - Replace pattern with replacement
🔄 s/old/new/ = substitute(替换) - 用替换内容替换模式
🌍 g = global - Replace all occurrences, not just first
🌍 g = global(全局) - 替换所有出现,不仅仅是第一次
💾 -i = in-place - Edit the file directly (be careful!)
💾 -i = in-place(就地) - 直接编辑文件(小心!)
🗑️ d = delete - Delete specified lines
🗑️ d = delete(删除) - 删除指定的行
🖨️ p = print - Print specified lines (use with -n)
🖨️ p = print(打印) - 打印指定的行(与-n一起使用)