sed, awk (gawk), and Perl


As a programmer, I like the Unix commands “find” and “grep”. They are too good. “find” to find the files recursively based on file name, file type, etc, then execute command towards the files.

“grep” is even more better, when I want to find some words in the source code, and I can use regular expression. Combine “grep” with “sed”, one can perform search and replace.

However, when I want to search and replace for multiple patterns, “sed” will be difficult to be used. One can write a shell script to perform the task. But “awk” (or GNU awk) will be a better solution for me. Write an awk script, can search and replace easier, and awk script allows to use variables.

But, “awk” is not good enough. “awk” is difficult to perform search and replace with regular expression that needs backreferences and lazy quantifier. To do these tasks, Perl is the best!

Yes! I never thought that Perl is that good. Because for me, using Perl to do web development is more difficult than using PHP. Using Perl to write an application is not better than using C/C++, because it is an interpreted language, not compiled language. But, if using Perl as a programmer’s tool, it is good for everything. Recursive file renaming with regular expression and recursive search and replace with regular expression, I can only solve these two tasks with Perl script.

(Though I was taught to use zsh to perform recursive file renaming with regular expression, but now I think Perl script is powerful enough.)

Advertisements

Upgrade to Ubuntu 10.10 on HP Mini


This is not an easy work for me.

  1. Firstly, I download the Ubuntu 10.10 alternative CD ISO.
  2. Then, following upgrade using the shell script by following this article.
  3. Restart

No wireless device detected, cannot connect internet through WiFi. What the X?! I used this method before by upgrading from 9.10 to 10.4, but this time fail.

  1. Then use the broadband connect to the internet
  2. System > Administration > Additional Drivers
  3. Download and update certain things, I don’t know what are they
  4. Found “Broadcom STA wireless driver”
  5. Activate
  6. Failed! Ask me to check /var/log/jockey.log

Then I think I need to update everything, so I run System > Administration > Update Manager. Then I asked for “Partial Upgrade”, and needs to download about 200Mb data. Not the good solution. Search solution online. Then I found this.

  1. sudo apt-get update
  2. Then I am asked to insert Ubuntu 10.10 Maverick
  3. So, I mount the alternative CD iso again
  4. Luckily it works
  5. sudo apt-get install bcmwl-kernel-source
  6. Restart

Yeah! Successfully upgraded, and can use the wireless device. But if go to Update Manager, I still need to download 200Mb for the Partial Upgrade. Not good, not good!