1、創建測試數據
[root@linuxprobe test]# echo "aaa.bbb.ccc.ddd" > a.txt [root@linuxprobe test]# cat a.txt aaa.bbb.ccc.ddd
2、利用\進行轉義,使轉義字符仍為字符串
[root@linuxprobe test]# sed 's/./ /' a.txt ## 利用sed命令進行替換,將.替換為空格, .沒有轉義前表示任意字符,僅第一個a被替換為空格 aa.bbb.ccc.ddd [root@linuxprobe test]# sed 's/\./ /' a.txt ## 加轉義字符\,.為普通字符串,被替換為空格 aaa bbb.ccc.ddd
[root@linuxprobe test]# sed 's/\./ /g' a.txt ## 加g表示全局替換,所有的.都被替換為空格
aaa bbb ccc ddd
3、' '將變量保持為普通字符串," "保持變量的原有屬性
[root@linuxprobe test]# ls a.txt [root@linuxprobe test]# cat a.txt aaa.bbb.ccc.ddd [root@linuxprobe test]# x=5 ##自定義變量 x等於5 [root@linuxprobe test]# echo $x ##查看變量 5 [root@linuxprobe test]# sed 's/b/$x/g' a.txt ## ' '將變量保持為普通字符串,所有的b被替換為$x aaa.$x$x$x.ccc.ddd [root@linuxprobe test]# sed "s/b/$x/g" a.txt ## " " 保持變量原有屬性,所有的b被替換為5 aaa.555.ccc.ddd
4、` ` 表示返回命令執行后的結果
[root@linuxprobe test]# for i in `seq 5`;do echo $i;done ## 將seq 5執行的結果返回給變量i 1
2
3
4
5 [root@linuxprobe test]# ls a.txt [root@linuxprobe test]# find * a.txt [root@linuxprobe test]# find * | sed "s#^#`pwd`/#" ## 在a.txt文件前加絕對路徑,利用sed在a.txt前添加pwd執行后的結果
/home/linuxprobe/data/sheepreq/fasta/test/test/a.txt