使用BASH或awk或sed或其他方法删除文件的前两行 [英] Deleting the first two lines of a file using BASH or awk or sed or whatever

查看:118
本文介绍了使用BASH或awk或sed或其他方法删除文件的前两行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图通过不将其打印到另一个文件来删除该文件的前两行.我不是在找花哨的东西.这是我对awk的尝试(失败):

I'm trying to delete the first two lines of a file by just not printing it to another file. I'm not looking for something fancy. Here's my (failed) attempt at awk:

awk '{ (NR > 2) {print} }' myfile

抛出以下错误:

awk: { NR > 2 {print} }
awk:          ^ syntax error

示例:

"myfile"的内容:

contents of 'myfile':

blah
blahsdfsj
1 
2
3
4

我想要的结果是:

1
2
3
4

推荐答案

使用tail:

tail -n+3 file

从手册页:

   -n, --lines=K
          output the last K lines, instead of the last 10; or use  -n  +K
          to output lines starting with the Kth

这篇关于使用BASH或awk或sed或其他方法删除文件的前两行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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