View Single Post
  #4   (View Single Post)  
Old 28th January 2010
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,319
Default

Quote:
Originally Posted by wesley View Post
It is very technical... hard to understand all...
J65nko is simply showing how awk(1) can be used to change the formatting of information found in /etc/fstab. Note that similar results can be seen in the output of mount(8). Although I have not spoken to J65nko about his intentions, I suspect he is wanting to start conversation with the membership at large about how the scripting languages found in all members of the *BSD family can be used to perform a number of trivial tasks without in-depth knowledge or experience in programming. Unix began with a culture assuming that users were astute enough to use the tools available to save them time, & much of that culture still exists today. The fact that you are asking questions means that J65nko has had some success.

Although the code provided does not do anything extensive, what needs to be supplied to awk(1)'s interpreter to perform this formatting is not that complicated either. In fact, a point being made is that with nominal knowledge of what awk(1) does & does well, it serves as a good tool to solve this particular type of problem. Other scripting languages can do the same thing, but other scripting languages also come from different backgrounds. The mindset needed to write similar code will result in completely different scripts. I urge others to take this same problem & implement a similar solution in other languages. The point is not to pit one language against another, but point out differences in their underlying assumptions.

Just to quickly explain the methodology of awk(1) scripts, awk(1) is very good at batch processing -- performing the same tasks to each & every row in a file (preferably text files...). In meeting this goal:
  • There may (or may not) be some pre-processing which needs to be done before starting
  • repeatedly performing a different set of tasks on each row in a file
  • followed (possibly) by a summary at the end
You may see that this described what needs to be done in any report -- output header information, churn through all rows, followed by providing totals at the end. awk(1) does this with:
  • an optional BEGIN block (which is executed only once if present...)
  • followed by a unnamed block which processes each record
  • followed by an optional END block (which is also only executed once if present...)
J65nko didn't provide an END block because in this particular problem, it was not needed. However, the language implemented by an awk(1) interpreter is rich enough to provide the functionality if such summation is required.

As for where to find more information on awk(1):
  • The best book introducing awk(1) (in my estimation...) is Aho, Weinberger, & Kernighan (& if you look at the last names long enough, you may see where the language got its name...):

    http://www.amazon.com/AWK-Programmin...4658668&sr=8-2

    If you are really interested in learning about awk(1), go to a library & read it. Other books have been published. You may find some at your local library too.
  • A brute force Web search:

    http://www.google.com/#hl=en&source=...df356c6a3f8304

    ...will also result in displaying a number of sites which discuss the idiosyncrasies of awk(1) programming.
  • And as already mentioned, the awk(1) manpage itself distills this information into a concise document.
Quote:
Why don't you build guide for novice users?
In a perfect world this might be possible, but you are asking people to invest significant time into writing detailed documents when they don't have the time. Online forums aren't the best venue for presenting extended lectures either. However, you are invited to read the following threads which describes what forums do best:Study up, & come back with more specific questions.

Reply With Quote