看板 RegExp 關於我們 聯絡資訊
我用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當起點, 再從那邊開始擷取? -- "Don't hate the player. Hate the game." 當看到哪個名人賺了大錢,領到高額補助或利息,不要去指責他, 而是要指責那個制度、創造那個制度的人,以及默許那個制度的人。 不然你認為一個人不領18%或是一個人不炒房價,就會改變整體環境嗎? 還不如改變【修改制度的人】,才能從根源改變一切。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.176.36.217 ※ 文章網址: https://www.ptt.cc/bbs/RegExp/M.1459822763.A.048.html
weiclin: dosomething | sed -n '/^Number/,$p' 04/05 11:05
LIAR: 我以為sed是以行為單位,可以用貪婪直接抓到全部結束啊? 04/05 11:21
LIAR: 這種sed用法真的沒看過,受教了 04/05 11:26
LPH66: 這個用法是 /^Number/,$ 指定符合 /^Number/ 那行到結束 04/05 17:33
LPH66: 在這個範圍內執行 p 指令印出該行 04/05 17:33
LPH66: 原本會印的每一行由 -n 抑制了 04/05 17:33