看板 Linux 關於我們 聯絡資訊
如題。 在Vim內要如何把搜尋到的結果字串另外存到一個 new file 呢? 問了G大神還是沒問到... -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.177.111.28 ※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1547870924.A.600.html
chang0206: https://is.gd/BvWhQD 這個不能用? 01/19 12:29
jasonlee1001: 我照著用 :g/regex/ .w >> res.txt 出現 01/19 16:34
jasonlee1001: E212: Can't open file for writing 01/19 16:34
jasonlee1001: https://imgur.com/mVKleYL 01/19 16:44
jasonlee1001: w後面加"!"已可寫出res.txt, 但寫出的是整行,有辦 01/19 16:54
jasonlee1001: 法可以只寫出所搜尋到的字串就好嗎? 01/19 16:55
Bencrie: 不考慮直接用 grep -o regex > output.txt 嗎 01/19 17:40
jasonlee1001: grep是辦得到,只是我想說在vi裡面看檔案時直接輸出 01/19 17:56
chang0206: 你是說mem前面的都不要?那不就改一下regex就好? 01/19 17:57
jasonlee1001: 對 我只要訊號名稱,但卻會寫出整行, regex已經鎖住 01/19 18:00
jasonlee1001: 訊號名稱了 01/19 18:00
jasonlee1001: Bencrie,你的方法可以輸出我想要的,只是就是要在另 01/19 18:01
jasonlee1001: 一個terminal grep出來... 01/19 18:02
Bellkna: 在新buffer然後用0read ! 配合外部命令再存會不會較省事? 01/19 19:41
hijkxyzuw: 有 editor 板 01/19 20:09
jasonlee1001: sorry不知有editor版,謝謝 01/19 21:54
kdjf: :w !grep -o regex > output 01/20 19:03
Arbin: 哇 頭一次知道有editor板... 01/26 17:41