动作:p 打印 eg: sed -n '(行)p' student.txt
a 行后增加新的一行,i 行前增加新的一行
sed '1,5a =============' student.txt
sed '/正则/a ============' student.txt
d 删除某行
sed '/正则/d' student.txt
sed '4d' student.txt
c 替换指定行
sed '2c canglaoshi bujigee' student.txt
sed '/正则/c lalalalalalala' student.txt
s 替换指定字符串(替换每行第一个);结尾g表示每一行所有
sed '/正则(定位行)/s/正则(旧)/abcd(新)/' student.txt
sed 's/正则(旧)/abcd(新)/' student.txt (全文替换)
sed '/www/s/33/000/g' zz_test.txt
操作:{}多个命令组合,用;分开
sed '{1,20p;s/www/s/33/000//g}'
& 取原字符
sed 's/abc/&def' student.txt (把abc换成abcdef)
u 字符串首字母改成大写
sed 's/abc/\u&/' student.txt (把abc改成Abc)
l 字符串首字母改成小写
U 字符串所有字母改成大写
sed 's/abc/\U&/' student.txt (把abc改成ABC)
L 字符串所有字母改成小写
r 将某文件插入到另一文件的指定行中
sed '1r abc.txt' 123.txt (将abc.txt中的内容插入到123.txt文件的第1行)
q 退出sed
sed '/false/q' student.txt (找到一个false就退出sed)