[英]Sed command not working as expected for delete particular line from file
I have try to use sed
command for delete particular line from file but it seems not working properly in my system (CentOS release 6.3 (Final).我尝试使用sed
命令从文件中删除特定行,但它在我的系统中似乎无法正常工作(CentOS 6.3 版(最终版))。
my file1.txt contain following data我的 file1.txt 包含以下数据
line1
line2
line3
line4
line5
Now i try below command to delete 3rd line from the file.现在我尝试下面的命令从文件中删除第三行。
$ sed '3d' file1.txt
And output of above command is上面命令的输出是
line1
line2
line4
line5
But when i check original file then it seems nothing deleted.但是当我检查原始文件时,似乎没有删除任何内容。 3rd line is there.第 3 行在那里。
So any one have idea why sed
not working?所以有人知道为什么sed
不起作用吗?
使其在线 sed:
sed -i.bak '3d' file1.txt
To delete particular lines from a file using sed
without creating a backup:要使用sed
从文件中删除特定行而不创建备份:
sed -i '' -e '3,6d' file1.txt
The command above will remove lines 3 up to and including 6 from file1.txt
, without creating a backup上面的命令将从file1.txt
删除第 3 行到第 6 行(包括第 6 行),而不创建备份
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.