rgpipe
1.0.0
rgpipe是一個bash/sh腳本,也是與ripgrep一起使用的別名,以搜索無數不友好的文件類型。將其與RIPGREP的-PRE命令一起使用,該命令允許RIPGREP在搜索之前選擇性處理文件。
最基本的用法是將rgpipe指向某些文件,它將嘗試將所述文件的內容打印到STDOUT。
rgpipe MyFancyExcelFile.xlsx
涉及的用法越多,是在Ripgrep面前的過濾器,以系統地嘗試瀏覽各種非文本文件的內容,就像您的文本文件一樣。基本的咒語看起來像:
rg --pre-glob '*.{xlsx,pptx,docx,pdf}' --pre rgpipe "$YourSearchTermHere"
我寫了一個關於如何在這裡使用它的長篇大論
這種要點僅是有用的,因為Burntsushi在此黑客新聞評論中說明了rg --pre-glob工作方式。
這有助於解決:
unzip和sedstringsunzip和sedpdftottextw3m lynx和朋友也有效。不是100%必需的。unzip和w3m for epub7zip和w3m ubuntu想要: sudo apt install poppler-utils p7zip w3m unzip
術語想要: pkg install poppler p7zip w3m
假設rgpipe在路徑中,如果不是
rg --pre rgpipe YourSearchTermHere上面使用rgpipe,即使不需要它,速度很慢,ripgrep可以選擇性地使用-pre-glob
rg --pre-glob ' *.{xlsx,pptx,docx,pdf} ' --pre rgpipe YourSearchTermHere一個更徹底的預遍:
rg --pre-glob ' *.{pdf,xl[tas][bxm],xl[wsrta],do[ct],do[ct][xm],p[po]t[xm],p[op]t,html,htm,xhtm,xhtml,epub,chm,od[stp]} ' --pre rgpipe YourSearchTermHere別名,因為那是很多打字
alias rgg= " rg -i -z --max-columns-preview --max-columns 500 --hidden --no-ignore --pre-glob
'*.{pdf,xl[tas][bxm],xl[wsrta],do[ct],do[ct][xm],p[po]t[xm],p[op]t,html,htm,xhtm,xhtml,epub,chm,od[stp]}' --pre rgpipe "步驟1:使用rgpipe製作文本邊防文件
find-rgpipe-type () {
find ` pwd ` -type f -iname " *. $1 " -exec sh -c ' for f; do rgpipe "$f" > "${f%.*}.txt"; done ' _ {} +
}
# or get fancy with xargs for multithreaded goodness
find-rgpipe-type-xargs () {
find " $( pwd ) " -type f -iname " *. $1 " -print0 | xargs -0 -P0 -n 1 -I {} sh -c ' rgpipe "{}" > "{}.txt" '
}
使用上面定義的函數,在當前目錄下為所有具有PDF擴展的文件進行文本側碼。
find-rgpipe-type pdf步驟2:使用RIPGREP搜索這些文件
rg YourSearchTermHere1-這篇黑客新聞評論
2-預處理腳本是我添加了更多文件類型的模板
3-午夜指揮官在這個主題上有很棒的腳本
4-少管當然
5 -RGA是一種基於生鏽的工具做類似的事情
rgpipe ,因為這個想法類似於小管子。