sed刪除文件中的一行內容的腳本代碼
更新時間:2013年03月02日 19:23:05 作者:
sed刪除文件中的一行內容的腳本代碼,需要的朋友可以參考下
先來看下原始文件的內容:
root@localhost ~]# cat file.txt
hello world
a:b:c -h -n
a:b:c -h -n
sed根據條件刪除相關的行:
[root@localhost ~]# sed -i '/a:b:c -h -n/d' file.txt
[root@localhost ~]# cat file.txt
hello world
sed根據條件進行相關內容的替換:
[root@localhost ~]# sed -i 's/hello/baidu/' file.sh
[root@localhost ~]# cat file.sh
baidu world
復制代碼 代碼如下:
root@localhost ~]# cat file.txt
hello world
a:b:c -h -n
a:b:c -h -n
sed根據條件刪除相關的行:
復制代碼 代碼如下:
[root@localhost ~]# sed -i '/a:b:c -h -n/d' file.txt
[root@localhost ~]# cat file.txt
hello world
sed根據條件進行相關內容的替換:
復制代碼 代碼如下:
[root@localhost ~]# sed -i 's/hello/baidu/' file.sh
[root@localhost ~]# cat file.sh
baidu world
相關文章
linux shell中 if else以及大于、小于、等于邏輯表達式介紹
在linux shell編程中,大多數情況下,可以使用測試命令來對條件進行測試,這里簡單的介紹下,方便需要的朋友2013-02-02linux Shell入門:掌握Linux,OS X,Unix的Shell環(huán)境
這篇文章主要介紹了linux Shell入門:掌握Linux,OS X,Unix的Shell環(huán)境 ,需要的朋友可以參考下2015-04-04詳解systemctl?和?service?區(qū)別及命令
systemctl和service都是管理Linux系統(tǒng)服務的工具,但systemctl更加先進,可以方便地管理systemd服務,而service適用于管理傳統(tǒng)的SysV服務,這篇文章主要介紹了systemctl和service區(qū)別及命令,需要的朋友可以參考下2023-07-07