使用unix shell脚本从文件中删除一行

时间:2016-02-25 01:31:31

标签: linux shell unix

我正在使用一个简单的shell脚本,如果找到在命令行输入的字符串,则需要从文件中删除一行。相反,它会删除文件的全部内容。

数据文件是这样的(每个条目都在一个新行上):

Name:Address:Phone:email
Joshua Brown:42404 Transport Center:380-(605)964-4223:jbrown0@desdev.cn
Margaret Elliott:24 Forest Plaza:48-(269)541-4040:melliott1@toplist.cz
Gary Flores:76868 Westport Drive:86-(478)534-8313:gflores2@reference.com

我的代码:

#assuming $1 is the pattern that needs to be searched for
#if found, delete the entire line
sed -i '/$1/d' filename

1 个答案:

答案 0 :(得分:0)

sed  -i 'Nd' filename

N表示行号,从1开始

相关问题