Pages

25 November 2009

Why so serious? :D

Got this quote from kernelnewbies mailing list....hehehehheheheh :D

"What happens when you read some doc and either it doesn't answer your question or is demonstrably wrong? In Linux, you say "Linux sucks" and go read the code. In Windows/Oracle/etc you say "Windows sucks" and start banging your head  against the wall."

-Denis Vlasenko on lkml

PS: s/banging your head*wall/take it for granted/g is better I guess :D I believe many Linux users also bang his/her head when learning Linux for the first time. :))

Moral: just don't bang your head too hard, it hurts, you know? :D

09 November 2009

how to catch white space(s) using grep?

My definition: White space characters are anything that appears as "blank" a.k.a nothing in screen. They include tab, space, carriage return and so on.

As you know, grep provides a way to catch certain characters class or range. Specifically for white spaces, you can use [[:space:]] or [[:blank:]]. Notice the double [[ and ]] !!!

So, suppose you have text file named test.txt that contains:

     hehe /var/www/
hehe /var/www2/
ttt hehe /var/www3/
     heho /var/www/

Executing:

$ grep ^hehe test.txt

will yield:

hehe /var/www2/

but this:

$ grep -E '^[[:blank:]]*hehe' test.txt

yields:

       hehe /var/www/
hehe /var/www2/

In human words, '[[:blank:]]*' will catch zero or more appearance of space or tab before the word "hehe". If you want to catch at least single appearance of any of them, use "+" instead. Oh and let me remind you again, use -E so that "+" doesn't lose its special meaning.

Note: initially, i thought i simply use [:space:] or [:blank:] and end up in something-is-wrong-but-I-dont-know-what land. Turns out, I didn't read the man page carefully (poor me). Since they are built-in classes, I still need to enclose them with another "[" and "]". Valuable experience.....

regards,

Mulyadi.