LInuxcmdsed
  LInux_cmd_sed
[toc]
# 空行
| 命令 | 说明 | 
|---|---|
sed G testfile |  每行后面添加一行空行 | 
sed '{x;p;x;}' testfile |  每行前面添加一行空行 | 
sed  'G;G'  testfile |  每行后面添加两行空行 | 
sed '{x;p;x;x;p;x;}' testfile |  每行前面添加两行空行 | 
sed '/^$/d' testfile |  删除空行 | 
sed '/shui/{x;p;x;G}' testfile |  匹配行前后添加空行 | 
sed '/^xi/{x;p;x;}' testfile |  以xi为开头的行前面添加空行 | 
sed '/xi$/G;' testfile |  以xi为结尾的行后面添加空行 | 
# 删除行
| 命令 | 说明 | 
|---|---|
sed '2,3d' data6.txt |  删除 data6.txt 文件内容中的第 2、3行 | 
sed '/1/,/3/d' data6.txt |  删除某个区间内的行 | 
sed '3,$d' data6.txt |  sed '3,$d' data6.txt | 
sed '3i\ This is an inserted line.' data6.txt |  第三行前插入新行(\:插入多行) | 
sed '3a\ This is an inserted line.' data6.txt |  第三行后插入新行(\:插入多行 | 
[address]c\用于替换的新文本 |  [替换模板](:固定格式) | 
sed '3c\ This is a changed line of text.' data6.txt |  替换第三行 | 
sed '/number 3/c\ This is a changed line of text.' data6.txt |  替换第三行 | 
sed '1ci ' data6.txt |  删除 data6.txt 文件内容中的第 2、3行 | 
上次更新: 2023/10/10, 14:48:21