How do you delete all lines in a file that begin with "string" in sh? I was thinking about using the sed command.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
grep -v '^string' yourfile.txt > stripped.txt
回答2:
To do it in place, if your sed supports the -i option, you can do:
sed -i '/^string/d' input-file
回答3:
sed and grep in your answers are missing their friend awk:
awk '!/^string/' inputfile > resultfile
回答4:
You can use Vim in Ex mode:
ex -sc g/^string/d -cx file
g
select all matching linesd
deletex
save and close