Linux的头/尾带偏移 [英] Linux head/tail with offset

查看:87
本文介绍了Linux的头/尾带偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在Linux下的方式索要头部或尾部,但有一个附加的记录忽略的偏移。

Is there a way in Linux to ask for the Head or Tail but with an additional offset of records to ignore.

例如,如果该文件 example.lst 包含以下内容:

For example if the file example.lst contains the following:

row01
row02
row03
row04
row05

和我使用头-n3 example.lst 我可以得到行1 - 3,但如果我想它跳过第一行,并得到行2 - 4?

And I use head -n3 example.lst I can get rows 1 - 3 but what if I want it to skip the first row and get rows 2 - 4?

我问,因为一些命令有可能不是在搜索结果中最好的头部。例如杜-h〜--max深度1 |排序-RH 将返回降序排列的主目录中的所有文件夹的目录大小,但将当前目录追加到结果集(即)。

I ask because some commands have a header which may not be desirable within the search results. For example du -h ~ --max-depth 1 | sort -rh will return the directory size of all folders within the home directory sorted in descending order but will append the current directory to the top of the result set (i.e. ~).

的头部和尾部手册页似乎没有任何偏移参数,这样也许有某种范围命令,其中所需的线路可以指定:例如范围2-10 还是什么?

The Head and Tail man pages don't seem to have any offset parameter so maybe there is some kind of range command where the required lines can be specified: e.g. range 2-10 or something?

推荐答案

男子尾

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

您可以使用,因此 ... |尾-n +2 |头-n 3 拿到3线从2号线开始。

You can therefore use ... | tail -n +2 | head -n 3 to get 3 lines starting from line 2.

无头/尾的方法包括 SED -n2,4p awk的NR> = 2及和放大器; NR < = 4

Non-head/tail methods include sed -n "2,4p" and awk "NR >= 2 && NR <= 4".

这篇关于Linux的头/尾带偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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