1、將空格替換成換行
sed "s/ /\n/g" yum.old.txt
2 將換行替換成空格
cat yum.new3.txt |tr "\n" " "
2、將每一行最後的空格+\替換掉
sed "s/ [\]$//g" yum.new.txt
3、在每一行最後添加 \
sed "s/$/ \\\/g" yum.new3.txt
4、將文本中每行字符串後面的空格去掉
#原文件
[root@docker soft]# cat -A test.txt
huilong$
uc $
sso $
index $
hq $
static $
news $
#匹配規則 空格加*表示匹配任意多個空格
[root@docker soft]# sed "s/ *$//g" test.txt > test2.txt
#最終結果
[root@docker soft]# cat -A test2.txt
huilong$
uc$
sso$
index$
hq$
static$
news$
5、將文件中每行字符後面拼接一段相同的字符串。
#原文件
[root@docker soft]# cat -A test2.txt
huilong$
uc$
sso$
index$
hq$
static$
news$
m.salon$
#例如在每行字符串結尾添加一個域名後綴.forex.com.cn
#匹配規則 測試ok
[root@docker soft]# sed "s/$/.forex.com.cn/g" test2.txt
huilong.forex.com.cn
uc.forex.com.cn
sso.forex.com.cn
index.forex.com.cn
hq.forex.com.cn
static.forex.com.cn
news.forex.com.cn
m.salon.forex.com.cn
6、去掉^M符號
sed -i 's/^M//g' filename
#注意^M符號的輸入方法,先按住CTRL,再分別按一下v和m