我正在嘗試從終端搜索pdf文件。我試圖從終端提供搜索字符串。搜索字符串可以是一個單詞,多個單詞(AND,OR)或一個精確的短語。我想只爲所有搜索查詢保留一個參數。我將把以下命令保存爲一個shell腳本,並將shell腳本作爲zsh或bash shell中的.aliases的別名進行調用。多種模式的一個參數 - grep
以下是sjr的回答,這裏是:search multiple pdf files。
我用SJR的回答是這樣的:
find ${1} -name '*.pdf' -exec sh -c 'pdftotext "{}" - |
grep -E -m'${2}' --line-buffered --label="{}" '"${3}"' '${4}'' \;
$1
採用路徑
$2
限制的結果數量
$3
是上下文參數(這是接受-A,-B ,-C,單獨或聯合)
$4
以搜索條件g
我面臨的問題是與$4
值。正如我前面所說,我希望這個參數傳遞我的搜索字符串,它可以是一個短語或一個字或多個單詞與/或關係。
我無法獲得理想的結果,直到現在我沒有獲得詞組搜索的搜索結果,直到我遵循Robin Green的評論。但仍然短語結果不準確。
編輯從判斷文本:
The original rule was that you could not claim for psychiatric injury in
negligence. There was no liability for psychiatric injury unless there was also
physical injury (Victorian Rly Commrs v Coultas [1888]). The courts were worried
both about fraudulent claims and that if they allowed claims, the floodgates would
open.
The claimant was 15 metres away behind a tram and did not see the accident but
later saw blood on the road. She suffered nervous shock and had a miscarriage. She
sued for negligence. The court held that it was not reasonably foreseeable that
someone so far away would suffer shock and no duty of care was owed.
White v Chief Constable of South Yorkshire [1998] The claimants were police
officers who all had some part in helping victims at Hillsborough and suffered
psychiatric injury. The House of Lords held that rescuers did not have a special
position and had to follow the normal rules for primary and secondary victims.
They were not in physical danger and not therefore primary victims. Neither could
they establish they had a close relationship with the injured so failed as
secondary victims. It is necessary to define `nervous shock' which is the rather
quaint term still sometimes used by lawyers for various kinds of
psychiatric injury...rest of para
word1
可以是:休克,(神經性休克)
word2
可以是:精神病
exact phrase
:(神經性休克)
命令
alias s='sh /path/shell/script.sh'
export p='path/pdf/files'
在終端:
s "$p" 10 -5 "word1/|word2" #for OR search
s "$p" 10 -5 "word1.*word2.*word3" #for AND search
s "$p" 10 -5 ""exact phrase"" #for phrase search
第二個測試樣品: 一個例子pdf文件,由於pdf文件命令運行:Test-File。它的4頁(361微克文件的一部分)
如果我們在其上運行下面的命令,作爲解決方案提到:
s "$p" 10 -5 'doctrine of basic structure' > ~/desktop/BSD.txt && open ~/desktop/BSD.txt
我們會得到相關的文字和「會避免穿通整個文件。認爲這將是一個很酷的方式來閱讀我們想要的,而不是傳統的方法。
爲什麼downvote?想要知道,以便在提問時我可以保重。 – lawsome
單引號將導致引用的參數不被擴展(假設您使用bash或sh),這不是您想要的。你應該使用雙引號來引用bash或sh中的參數。或者你正在使用其他一些shell? –
我沒有投票,我也希望人們在他們這樣做時會留下反饋。也就是說,將[MCVE(Minimal,Complete,and Verifiable Example)](http://stackoverflow.com/help/mcve)的問題減少到總是值得。有關提問的一般提示可以在這裏找到(http://stackoverflow.com/help/how-to-ask)。 – mklement0