linux sed


例子:
一.將linuxfocus 替換爲 LinuxFocus :cat text.file | sed 's/linuxfocus/LinuxFocus/' > newtext.file

二. 
sed -i 's/原字符串/新字符串/' /home/1.txt
sed -i 's/原字符串/新字符串/g' /home/1.txt
兩條有什麼區別呢?
1.txt原文檔
#cat 1.txt
d
ddd
#ff

sed -i 's/d/7523/' /home/1.txt

執行結果

7523dd

#ff


sed -i 's/d/7523/g' /home/1.txt

執行結果

752375237523

#ff


三。

去掉 “行首” 帶“@”的首字母@

sed -i 's/^@//' file

 

特定字符串的行前插入新行

sed -i '/特定字符串/i 新行字符串' file

 

特定字符串的行後插入新行

sed -i '/特定字符串/a 新行字符串' file

 

特定字符串的刪除

sed -i '/字符串/d' file


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章