Sed
- 全词替换
echo bar embarassment | sed 's/\bbar\b/BAR/g' echo bar embarassment | sed 's/\<bar\>/BAR/g'
- -i.bak 替换的同时备份原文件
1 Unix unix unix 23 2 linux Linux 34 3 linuxunix UnixLinux linux /bin/bash CentOS Linux OS Linux is free and opensource operating system
-
sed 's/search_string/replacement_string/2' sample 替换第二个
简单用法示例:https://linux.cn/article-11367-1.html -
行首或行尾添加内容
sed -i.bak '/^[[:lower:]]/ s#^#HEAD&#g' sample sed -i.bak '/^[[:digit:]]/ s#^#&TAIL#g' sample sed -i.bak '/./ s#^#HEAD&#;s#$#&TAIL#' sample
- 删除'\r'
sed -i 's/\r//g' sample
-
分组提取
echo "background-image: url(/media/images/index/im2.jpg);"|sed -nr 's|^.*url\((.+)\).*$|\1|p'
-
IGNORECASE