Hi.
Quote:
Originally Posted by pppaaarrrkkk
Thanks for replies, helpful all.
Shame AWK can't do it.
Conclusion is to use Python (or Perl), but that's another thread.
|
This is the other thread
From my perspective,
awk cannot deal with objects smaller than characters, so it does not do well if you need to process binary (non-text) files. However, as seen, it can be used to solve the problem cited, just not as compactly as one often sees for awk solutions.
As ghostdog74 has mentioned here or in other forums, awk is often faster than alternatives, such as
perl and
sed -- at least consuming less CPU time, I don't recall about real time, system time, or other resources, memory, etc.
For one-shot solutions, I often reach for awk. However, if I see that I can attack a class of problems with a little generalization, then I will usually craft a perl solution, often because of the large body of modules contributed by the perl community. These are often available with one's package manager, or, in the last resort, from
http://cpan.org/
I also usually write in a line-oriented sense. So in the thread above, one solution was, essentially:
The assignment was explained as reassembling the line. However, the trailing "1" might be mystifying. I would write it as:
because it really is two statements. Recall that the format for awk is a series of lines like:
Code:
expression { action }
if
expression is missing, it is taken to mean "always true" or "for every line".
If
{ action } is missing, it is taken to be
So the "1" really means
Code:
for every line { print whatever is in $0 }
because "1" is "true".
If I don't write it out or comment things like that, then in a month or so I'll forget what it means, and I'll need to spend time re-discovering what I was doing.
Best wishes ... cheers, makyo