sed刪除文件中的一行內(nèi)容的腳本代碼
更新時(shí)間:2013年03月02日 19:23:05 作者:
sed刪除文件中的一行內(nèi)容的腳本代碼,需要的朋友可以參考下
先來看下原始文件的內(nèi)容:
root@localhost ~]# cat file.txt
hello world
a:b:c -h -n
a:b:c -h -n
sed根據(jù)條件刪除相關(guān)的行:
[root@localhost ~]# sed -i '/a:b:c -h -n/d' file.txt
[root@localhost ~]# cat file.txt
hello world
sed根據(jù)條件進(jìn)行相關(guān)內(nèi)容的替換:
[root@localhost ~]# sed -i 's/hello/baidu/' file.sh
[root@localhost ~]# cat file.sh
baidu world
復(fù)制代碼 代碼如下:
root@localhost ~]# cat file.txt
hello world
a:b:c -h -n
a:b:c -h -n
sed根據(jù)條件刪除相關(guān)的行:
復(fù)制代碼 代碼如下:
[root@localhost ~]# sed -i '/a:b:c -h -n/d' file.txt
[root@localhost ~]# cat file.txt
hello world
sed根據(jù)條件進(jìn)行相關(guān)內(nèi)容的替換:
復(fù)制代碼 代碼如下:
[root@localhost ~]# sed -i 's/hello/baidu/' file.sh
[root@localhost ~]# cat file.sh
baidu world
相關(guān)文章
Linux應(yīng)用調(diào)試之strace命令詳解
strace常用來跟蹤進(jìn)程執(zhí)行時(shí)的系統(tǒng)調(diào)用和所接收的信號。下面通過本文給大家分享Linux應(yīng)用調(diào)試之strace命令,需要的朋友參考下吧2017-12-12
獲取同一網(wǎng)段下所有機(jī)器MAC地址的shell腳本
有時(shí)候需要在當(dāng)前同一網(wǎng)段下所有機(jī)器MAC地址,需要的朋友可以參考下2013-01-01
獲取磁盤IO與系統(tǒng)負(fù)載Load的shell腳本
本節(jié)介紹的幾段shell腳本,可以用于提取磁盤的I/O信息,系統(tǒng)負(fù)載Load信息等2013-08-08
Shell獲取當(dāng)前正在執(zhí)行腳本的絕對路徑
本文主要介紹了Shell獲取當(dāng)前正在執(zhí)行腳本的絕對路徑,主要有三種方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
script_tool_for_linux.bash: Linux 環(huán)境下的 hosts 一鍵部署腳本
這篇文章主要介紹了script_tool_for_linux.bash: Linux 環(huán)境下的 hosts 一鍵部署腳本,需要的朋友可以參考下2016-04-04

