Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Count Number of Fields in Each Line

Sometimes, a structured text file might be malformatted. A simple way to verify it is to count the number of fields in each line.

Using awk

You can count the number of fields in each line using the following awk command. Unfortunately, awk does not take escaped characters into consideration …

What are the Two Integers?

I met a friend majored in math on a bus home today. He held a piece of paper with a question (probably an interview question since he is trying to find a job recently). He asked the question to me and I found it to be an interesting one.

A …

Sun Bin PK Pang Juan

Dating back to the time when I was a sophomore, I read a very interesting problem from "Waming", which is a magazine of math department of USTC (University of Science and Technology of China).

One day Guigu Zi (a famous ancient Chinese sophist, the teacher of Sun Bin and Pang …