Bash工作代码以从文件中删除第一行或最后一行 [英] Bash working code to delete first or last line from file

查看:71
本文介绍了Bash工作代码以从文件中删除第一行或最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了sed示例,但是无论如何写,它都不会删除我的第一行.实际上,我进行了更多测试,并且也不会删除第一行,因此可以确定我做错了什么:

I saw the sed examples, but no matter how I write that it won't delete my first line. Actually, I did more tests and it won't delete my first line either, so for sure I'm doing something wrong:

sed '1d' filename

或最后一行

sed '$d' file name

我希望更改发生在同一个文件中,并且不希望另一个输出文件. 那么,请问删除文件最后一行的正确方法是什么?

I want the changes to take place in the same file, and don't want another output file. So please, what's the correct way to remove the last line in my file?

推荐答案

sed -i '$ d' filename. -i标志可在适当位置编辑文件.

sed -i '$ d' filename. The -i flag edits file in place.

这篇关于Bash工作代码以从文件中删除第一行或最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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