sed

first second third five 保存为123.txt

sed 是一种在线编辑器。 进入/root/shasha sed '/second/p' 123.txt

sed -n '/second/p' 123.txt 打印所在行

sed '$a \ > oo \ > last line ' 123.txt

sed '1i phper.yang' 123.txt 在第一行插入 sed '3a four' 123.txt 在第三行后面插入four sed '/five/i four' 123.txt 在five 面前插入four

sed '1,3d' 123.txt 删除一到三行

sed '$d' 123.txt 删除最后一行

sed '2d' 123.txt 删除第二行

sed '/^$/d' 123.txt 删除空行

sed '/^th/d' 123.txt 删除th开头的

sed 's/^..//' 123.txt 删除每行的前两个字符

sed 's/f/F/g' 123.txt 将所有的f替换成大写F

sed '1,2 s/d$/&dd/' 123.txt 在1-2行中,所有以d结尾字段后附加一个dd

sed '/first/ s/st/ST/' 123.txt 在含有first的行中,把st换成大写ST

sed 's/ /\t/g' yang.txt 将文中所有空格替换成TAB

sed 'y/five/six1/' 123.txt 通常用于大小写转换。

sed -n '/second/,/five/ p' 123.txt 输出second和five中间的数据,此处不加-n会出现重复

sed '/second/,/five/ s/i/IIII/' 123.txt 修改second和five中间的数据,用III替换i

sed -e '1d' -e 's/^sec/2nd/' 123.txt 多次编辑

sed '/second/r yang.txt' 123.txt 匹配上second后,在其后读入文件

sed '/second/w write' 123.txt cat write 匹配上second后把该行写入到文件

q提前退出,h和g暂存与取用,x暂存和互换