[问题] 如何从特定行后开始处理?

楼主: LIAR (玻璃做的大叔)   2016-04-05 10:19:20
我用linux 的bash,有时输出的stdout前面会有一些警告或其他不相关的资讯
譬如gdisk你有没有GPT的输出就会不一样,但是我只要抓后面的分割表资讯
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory.
***************************************************************
Warning! Secondary partition table overlaps the last partition by
33 blocks!
You will need to delete this partition or resize it in another utility.
Disk /dev/sda: 2930275055 sectors, 1.4 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): B39B51E9-4599-4F74-93A2-294DF2860F14
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 2930275021
Partitions will be aligned on 8-sector boundaries
Total free space is 35699733 sectors (17.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 63 1646699 804.0 MiB 8300 Linux filesystem
2 1690000 5450000 1.8 GiB 8300 Linux filesystem
3 5559999 11979999 3.1 GiB 8300 Linux filesystem
5 11999999 17187199 2.5 GiB 8300 Linux filesystem
6 17187299 19045799 907.5 MiB 8300 Linux filesystem
7 20000000 25329999 2.5 GiB 8300 Linux filesystem
也就是蓝色部分。唯一的共通点我看就是在 红色那行的下面。
我有想过抓数字开头,但是绿色那行会被抓到。
虽然可能还可以加上空白解决这个案例的要求,
不过我想请问的是有没有通用的,真的根据特定文字行当作一个tag当起点,
再从那边开始撷取?
作者: weiclin (CC)   2016-04-05 11:05:00
dosomething | sed -n '/^Number/,$p'
楼主: LIAR (玻璃做的大叔)   2016-04-05 11:21:00
我以为sed是以行为单位,可以用贪婪直接抓到全部结束啊?这种sed用法真的没看过,受教了
作者: LPH66 (-6.2598534e+18f)   2016-04-05 17:33:00
这个用法是 /^Number/,$ 指定符合 /^Number/ 那行到结束在这个范围内执行 p 指令印出该行原本会印的每一行由 -n 抑制了

Links booklink

Contact Us: admin [ a t ] ucptt.com