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.)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s