あなたができるすべてをGrep

すべてではないにしても、 Habrの多くの読者は grep



について知っていますが、多数の親relativeを知っている人はほとんどいません。











少なくとも一粒のテキストであふれているすべてのものをつかむ方法を見つけましょう。







pgrep



pgrep



コマンドは、実行可能プロセスのリストを取得します。







 (5:573)$ pgrep bash 1772 11003 20678
      
      





-a



スイッチを使用すると、コマンドはコマンドライン全体も表示します。







 (5:574)$ pgrep -af bash 1772 -bash 11003 /bin/bash 20678 /bin/bash 23567 -bash
      
      





ps



pgrep



正しく組み合わせた場合、結果はおそらくps -ef |grep process_name



より便利ですps -ef |grep process_name



コマンド自体が含まれていないためです。







 (5:575)$ ps wup $(pgrep bash) USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1772 0.0 0.0 21572 3020 tty1 S+ 19 0:00 -bash user 11003 0.0 0.0 21384 3772 pts/3 Ss 28 0:00 /bin/bash user 20678 0.0 0.0 21396 3604 pts/1 Ss+ 24 0:00 /bin/bash root 23567 0.0 0.0 21364 3016 tty2 S+ 21 0:00 -bash 946/7720MB 0.48 0.94 1.00 1/352 20403
      
      





zipgrep、zfgrep、bzfgrep、xzfgrep



これらのコマンドを使用して、アーカイブからキーワード、パターンを直接検索できます。







 (5:576)$ zipgrep -i exception apptrace.zip jboss.stderr:java.lang.NumberFormatException: For input string: "4718-4e99-bc84-828a7bf7f254" jboss.stderr: at java.lang.NumberFormatException.(NumberFormatException.java:65) (5:576)$ (5:576)$ bzfgrep -w bugs /usr/share/doc/coreutils-8.25/README.bz2 that distribution and found and reported bugs. <http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/12292/focus=12318>. see <http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/12015/>. Reporting bugs: subtle bugs. When reporting bugs, please include in the subject line both the package
      
      





ユーティリティは拡張正規表現をサポートし、独自のegrep



同等物を持っています。







固定ストリング 基本的な正規表現 拡張正規表現
zfgrep zgrep ゼグレップ
bzfgrep bzgrep bzegrep
xzfgrep xzgrep xzegrep


どのパッケージに属しますか?







 (5:777)$ equery belongs $(which zgrep zipgrep bzgrep xzgrep) * Searching for /usr/bin/zgrep,/usr/bin/zipgrep,/usr/bin/bzgrep,/usr/bin/xzgrep ... app-arch/bzip2-1.0.6-r7 (/usr/bin/bzgrep) app-arch/gzip-1.8 (/usr/bin/zgrep) app-arch/unzip-6.0_p20 (/usr/bin/zipgrep) app-arch/xz-utils-5.2.2 (/usr/bin/xzgrep)
      
      





拡張レギュラーを解析して結果を楽しむ機能をgrep



比較してください。







 (5:578) grep -oE '\b[0-9]{1,3}(\.[0-9]{1,3}){3}\b' /var/log/emerge.log |tail -n 3 7.2.6.8 213.180.204.183 213.180.204.183 (5:579) (5:579) bzegrep -o '\b[0-9]{1,3}(\.[0-9]{1,3}){3}\b' /tmp/emerge.log.bz2 |tail -n3 7.2.6.8 213.180.204.183 213.180.204.183
      
      





pdfgrep



プログラムには同じパッケージが付属しています。







 (5:580)$ eix pdfgrep [I] app-text/pdfgrep  : 1.3.2 1.4.1-r1 {+pcre test unac}  : 1.4.1-r1(14:10:46 29.11.2016)(pcre -test -unac)  : http://pdfgrep.org/ : A tool similar to grep which searches text in PDFs
      
      





このコマンドはpdfファイルを解析し、 grep



が行うべきことをすべて実行します。







 (5:581)$ pdfgrep -i outdiscards ebook/linux_netw.pdf IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTDISCARDS);
      
      





Pdfgrep



拡張正規表現をサポートしていませんが、 非常に便利なプログラムです。 私はかなり頻繁にpdfsを開き、その中のテキストを探します。どの本で私が必要なもので、多くの時間を無駄にしていたかを思い出します。 今、私は知っています。







dgrep



Debianは、 debian dgrep



パッケージに付属しているdgrep



に精通している可能性があります 。 このコマンドは通常のgrep



と同じ方法で呼び出され、ファイルではなくパッケージの名前のみが示されます。

















固定ストリング 基本的な正規表現 拡張正規表現
dfgrep dgrep デグレップ
- dzgrep -


上位3つはテキストファイルで検索され、 dzgrep



はアーカイブファイルで検索されます。







msggrep、mboxgrep



これは、ローカライズディレクトリを解析するための非常に狭い専門の仕掛けです。 gettextパッケージが付属しています。 このプログラムはカスタムのカテゴリのものではありませんが、本当に必要な場合は、コマンドラインから実行できます。







 (5:752)$ msggrep -K -e help /usr/share/locale/ru/cups_ru.po
      
      





そして、そのような出力を画面に表示します
 msgid "" msgstr "" "Project-Id-Version: CUPS 2.0\n" "Report-Msgid-Bugs-To: http://www.cups.org/str.php\n" "POT-Creation-Date: 2015-07-20 14:24-0400\n" "PO-Revision-Date: 2015-01-28 12:00-0800\n" "Last-Translator: Aleksandr Proklov\n" "Language-Team: PuppyRus Linux Team\n" "Language: Russian\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" msgid " --help Show help." msgstr " --help  ." msgid " --help Show this help." msgstr " --help   ."
      
      





次の展示はmboxgrepメールボックスパーサーです。 プロジェクトは決して離陸せず、開発は中止されました。 理論的には、手紙のパターンを見つけて、出力を個別のファイルであるかのように処理する必要がありました。 ただし、初心者にとっては、これらのパターンを見つけることができなければなりません。







 (5:753)$ grep Inomics docs/PocoMail.bak/Mail/Trash.mbx From: Inomics <inomics-alert@inomics.com> Reply-To: Inomics <inomics-alert@inomics.com> Subject: Inomics Alert Service following is a list of new job openings in Inomics, the= Inomics! You can always unsubscribe from the Inomics Job Alert service by= plying to this mail with the words "Inomics-Job-Unsub#1avwnr55di"=
      
      





しかし、彼は見つけません。







 (5:754)$ mboxgrep Inomics docs/PocoMail.bak/Mail/Trash.mbx (5:755)$
      
      





奇妙なことに、 read



システムコールは、検索に関係なく常に同じです。







 (5:779)$ strace -e trace=read -o strace_inomics mboxgrep Inomics Mail/Trash.mbx (5:780)$ strace -e trace=read -o strace_freenet mboxgrep freenet Mail/Trash.mbx (5:781)$ diff strace_inomics strace_freenet;md5sum strace_* 14b7de546a2a776006ad2a6440b680fd strace_freenet 14b7de546a2a776006ad2a6440b680fd strace_inomics
      
      





このプログラムが誰かと正常に開始されたかどうかを知ることは興味深いでしょうか?

さて、私たちは夢中になりました、そして、グレープファミリーはまだ完全に目録化されていません。







ssgrep



Gnumericパッケージをインストールする必要があります。 独自のExcel形式を含むスプレッドシートを作成できます。 彼に誓うが、そうだ。







 (5:782)$ ssgrep Date files/*.xlsx     "43"     "41"     "44"     "42" Unexpected element 'workbookProtection' in state: workbook  /Date of Birth (5:783)$ grep Date files/*.xlsx (5:784)$
      
      





拡張正規表現はサポートされていません。 非常に便利なことをお勧めします。







ngrep



SourceForgeの別のプロジェクト 。 このプログラムはtcpdump



grep



ハイブリッドであり、最初のものは2番目のものよりもはるかに近いものです。







syslog



ポートとキーワードによるネットワークトラフィックの監視。







 $ ngrep -d any 'error' port syslog
      
      





ftp



ポートおよび大文字と小文字を区別しないキーワードでネットワークトラフィックを監視し、単語全体を比較します。







 $ ngrep -wi -d any 'user|pass' port 21
      
      





http



トラフィックの行http



出力。







 $ ngrep -W byline port 80 interface: eth0 (64.90.164.72/255.255.255.252) filter: ip and ( port 80 ) #### T 67.169.59.38:42177 -> 64.90.164.74:80 [AP] GET / HTTP/1.1. User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686) Opera ... Host: www.darkridge.com. Accept: text/html, application/xml;q=0.9, application/xhtml+xml;q=0.9 ... Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1. Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0. Cookie: SQMSESSID=5272f9ae21c07eca4dfd75f9a3cda22e. Cookie2: $Version=1. Cache-Control: no-cache. Connection: Keep-Alive, TE. TE: deflate, gzip, chunked, identity, trailers.
      
      





そして、 キラー機能があります。 ngrep



がパッケージのバイナリデータをマップする16進文字列を指定できます。 たとえば、ウイルスに感染したGIFの署名を指定して、ファイアウォールが早期に検出されるように構成できます。







 $ ngrep -xX '0xc5d5e5f55666768696a6b6c6d6e6' port 80 interface: eth0 (64.90.164.72/255.255.255.252) filter: ip and ( port 80 ) match: 0xc5d5e5f55666768696a6b6c6d6e6
      
      





プロジェクトの開発が中止されたことは残念ですが、最終的には非常に適しているかもしれません 自走式エンジン パーサーおよびネットワークトラフィックアナライザー。







ディープグレップ



最後に、KDE strigi-utilsのdeepgrepなどの非Unixスイープ集計に言及できます。







プログラムは 冗談を言う 形式ファイルで検索:









互いに埋め込まれたアーカイブを検索できます。







 $ deepgrep bar foo.ar foo.ar/foo.tar/foo.tar.gz/foo.zip/foo.tar.bz2/foo.txt.gz/foo.txt:foobar foo.ar/foo.tar/foo.tar.gz/foo.zip/foo.tar.bz2/foo.txt.gz/foo.txt:bar
      
      





欠点の。









使用材料






All Articles