sed 使用笔记
source link: https://deweyreed.github.io/2024/04/21/sed/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
sed 使用笔记
2024-04-21Notes
sed
替换
oldfile
文件中的每行第一个find
为replace
,保存内容到newfile
中sed 's/find/replace/' <oldfile >newfile
替换
oldfile
文件中的每一个<space>find
为replace
,保存内容到newfile
中sed 's/ find/replace/g' <oldfile >newfile
替换
filename
文件中的每一个find
为replace
sed -i 's/find/replace/g' filename
替换
filename
文件中的包含Replace
文字的每一行中的the
为THE
sed -i '/Replace/s/the/THE/g' filename
删除
filename
文件中的包含Replace
文字的每一行sed -i '/Replace/d' filename
不使用
-i
则打印内容运行多条命令
sed -i '...;...' filename
sed -i -e '...' -e '...' filename
\/
转义/
或使用s#find#replace#g
,s|find|replace|g
,.
打印出包含
usr
的每一行:sed '/user/p'
删除
redacted
:sed "s/redacted//g filename
删除空行:
sed "/^$/d" filename
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK