grep for Windows/DOS 復古的搜尋工具

用慣 unix / Linux 系統的人一定覺得命令列太好用了,加上 unix 上豐富的工具程式及 shell script,整個組合起來,豈是一個爽字可以形容… 視窗系統就是慢–點、點、點、選、點、點、放下滑鼠打字、選ok、ok、ok…

grep 應該是最好用的工具之一,用來搜尋文字檔案內特定的內容,有有心人在 Windows 也移植了它,在 可以抓到。

通常的用法像是
C> grep -i wp_title *.php
在 *.php 檔案中,尋找 wp_title 字串,-i 表示不管大小寫。
結果:
general-template.php:function wp_title($sep = '»', $display = true) {
general-template.php: $title = apply_filters('wp_title', $title, $sep);

在 *.php 檔案中,找到一個檔案 (general-template.php) 出現兩次 wp_title。

搭配 wc (word count),用 pipe 連起來
C> grep -i wp_title *.php | wc
結果:
2 14 150
算出結果有2列,14個字,150位元。如果結果有很多就愈顯好用。

包含 wc 的很多 unix 工具程式之 Windows/DOS 版可以在 取得,像 tail, gawk, sed, diff, patch 等等都很好用 ((unxutils 共包含下列 unix utilities: agrep, ansi2knr, basename, bc, bison, bunzip2, bzip2, bzip2recover, cat, chgrp, chmod, chown, cksum, cmp, comm, compress, cp, csplit, cut, date, dc, dd, df, diff, diff3, dircolors, dirname, du, echo, egrep, env, expand, expr, factor, fgrep, find, flex, fmt, fold, fsplit, gawk, gclip, gplay, grep, gsar, gunzip, gzip, head, id, indent, install, join, jwhois, less, lesskey, ln, logname, ls, m4, make, makedepend, makemsg, man, md5sum, mkdir, mkfifo, mknod, mv, mvdir, nl, od, paste, patch, pathchk, pclip, pr, printenv, printf, pwd, recode, rm, rman, rmdir, sdiff, sed, seq, shar, sleep, sort, split, stego, su, sum, sync, tac, tail, tar, tee, test, touch, tr, type, uname, unexpand, uniq, unrar, unshar, unzip, uudecode, uuencode, wc, wget, which, whoami, xargs, yes, zcat, zip)),裡面也有個 grep,不過找目錄下檔案的內容不 work,grep 以上述版本較佳。

(Visited 16,556 times, 1 visits today)

在〈grep for Windows/DOS 復古的搜尋工具〉中有 10 則留言

  1. 嘿嘿 喜歡用 command line 也是一個讓人知道你年齡的好方式
    講到 grep 就不得不提到 diff, 寫 shell script 的人大概也常用這個指令去比較檔案內容的不同處

    回覆
  2. command line 不太可能會消失 雖然各家都有GUI的 Admin tools 但是我從來沒看過那個系統管理的只會用視窗就可搞定一切 再說現在許多公司對於遠端登入的user 限制頗多(基於安全理由) 有時光是要傳輸UNIX or Linux 的 Xwindows 就要花一番時間去設定 (尤其是像我這種有時必須半夜起床”在家”登入系統的user) 還是 command line 卡實在

    回覆
  3. 哈哈哈 我的中打更糟 只能牽托:1. 我的pc沒有中文軟體 2.po了就不能再重改 就說是XXX一言既出 肆馬難追好了

    嚴格說來 還是有人用X windows的 網上google一下就有 下例就是:http://stein.cshl.org/genome_informatics/unix1/xwindows.html

    wikipedia 上則有這一段有些趣的描寫:People in the computer trade commonly shorten the phrase “X Window System” to “X11” or simply to “X”. The term “X Windows” (in the manner of “Microsoft Windows”) is not officially endorsed, though it has been in common use since early in the history of X and has been used deliberately for literary effect, for example in the UNIX-HATERS Handbook.[36] http://en.wikipedia.org/wiki/X_Window_System

    總之 X window 應是一般接受的terminology

    回覆
  4. 哈哈 2008球季就快到了 再等一下吧

    Christmas 是這裡一年內最重要的日子 拼著老命終於把戶外屋頂的燈飾給掛上去了 就是為了要給小朋友驚喜

    說到放假 我都是用自己的休假給他連續假期的 每年農曆新年都嘛在上班 明年看看能不能請個假

    回覆

發佈回覆給「老輔仔」的留言 取消回覆