2014/08/13

難纒的 Regular Expression


列出一些參考網站,
有空再來整理...

Unix - Regular Expressions with SED
Character Class
[[:alpha:]] Alphabetic [a-z A-Z]
[[:digit:]] Numbers [0-9]


http://txt2re.com/index.php3?s=01%3AAug%3A2014+%22This+is+an+Example%21%22&submit=Show+Matches

Regexper
http://www.regexper.com/


http://en.wikipedia.org/wiki/Regular_expression

http://blog.roodo.com/rocksaying/archives/2670695.html

http://www.regexr.com/

http://refiddle.com/

http://regex101.com/

http://rubular.com/


http://www.rexv.org/

http://regexpal.com/


正規表示式的入門與應用(二)
http://www.rtfiber.com.tw/~changyj/regex.2/

基礎正規表示法
http://dywang.csie.cyut.edu.tw/moodle23/dywang/linuxProgram/node22.html



Google Analytics Regular Expressions Cheat Sheet
http://www.cheatography.com/jay-taylor/cheat-sheets/google-analytics-regular-expressions/




2014/08/12

Shell Script 字串轉換小寫


[ Quick Solution Mode ]
寫 shell script 處理字串時,
偶爾會有將字串轉小寫的需求, 這裡列出三個易懂 好用的方法..
# 先看看原本變數內容
$ echo $str
HELLO WORLD

# Bash 4.0 (Bash 4.0 以後功能變得更強大了~)
$ echo ${str,,}
hello world

# tr
$ echo $str | tr '[:upper:]' '[:lower:]'
hello world

# awk ($0 表示 pipe 過來的完整字串)
$ echo $str | awk '{print tolower($0)}'
hello world

這裡還有人提出一些其他的解法, 有興趣的可以參考看看


2014/08/05

解決 WebApplication on Appache 網址路徑問題, 以及 codeigniter 移除 index.php 問題

今天早上終於解決了這兩個困擾我好久的問題!!!
實在是太興奮了 結果午睡睡不著 XD
腦袋無法停止思考....
想著接下來系統如何自動更新, 以及權限部分的問題...
原來之前就曾與解法擦肩而過,
之前真是鬼遮眼了....QQ"
所以....解法....待之後再補上...XDDDD
真是太開心了...haha

2014/08/01

Shell script: 計算檔案行數 (Count how many lines in a file)


[ Quick Solution Mode ]
$ cat test.log
aaaaa
bbbbb
ccccc
ddddd

# Way I
$ wc -l ./test.log         # -l, --lines: print the newline counts
4 ./test.log

# Way II
$ grep -c '' ./test.log    # -c, --count: print a count of matching lines
4

# Way III
$ sed -n '$=' ./test.log   # $: match last line, =:print current line number
4


[ Verbose Mode ]
由以上三種方法可以看出用 grep 或 sed 時只會回傳總行數,
如果需要用行數來做一些處理時就會比用 wc 來的方便

sed 的 -n 指的是 silent (安靜模式),
表示只顯示匹配的結果,
若不加就會將檔案內容也給輸出了,
所以通常使用 sed 時都會加上 -n 的參數