使用 sed 从文本文件中删除特定行号? [英] Delete specific line number(s) from a text file using sed?

查看:43
本文介绍了使用 sed 从文本文件中删除特定行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从文件中删除一个或多个特定的行号.我将如何使用 sed 做到这一点?

I want to delete one or more specific line numbers from a file. How would I do this using sed?

推荐答案

如果要删除第 5 行到第 10 行和第 12 行:

If you want to delete lines 5 through 10 and 12:

sed -e '5,10d;12d' file

这会将结果打印到屏幕上.如果要将结果保存到同一个文件中:

This will print the results to the screen. If you want to save the results to the same file:

sed -i.bak -e '5,10d;12d' file

这会将文件备份到 file.bak,并删除给定的行.

This will back the file up to file.bak, and delete the given lines.

注意:行号从 1 开始.文件的第一行是 1,而不是 0.

Note: Line numbers start at 1. The first line of the file is 1, not 0.

这篇关于使用 sed 从文本文件中删除特定行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆