Getting awk to extract scripts from a file
I am trying to write an awk extraction script that will extract scripts from a file called awkfile2. There are 4 scripts in awkfile2, written like this:
Quote:
So far this is what I have for my awk extraction script: Quote:
Can someone help? |
Moral of the story is don't.
Awk is far more difficult that it needs to be. I _strongly_ encourage you to use Ruby, Perl or Python for such tasks. Personally I rate Ruby a lot better than Perl or Python. http://www.ruby-lang.org |
Code:
awk 'BEGIN { FS = "*"; counter = 6 }\ other language. |
No, it is not difficult to understand and use. I have used it a lot.
It is just difficult to do many tasks. If your job is to iterate through a file matching certain patterns and perfoming an action on the line that matched that pattern. Awk is good. Many tasks fit that description. Many more tasks don't. Odds on if you are struggling to do something in awk, it will be trivial in Python or Perl or Ruby. Hence a generic answer to any question on "How do I do XXX in awk?" is "Don't. Do it in Perl or Python or Ruby." Because if they need to ask how on a forum such as this, it is more than likely a problem that is trivial in one of those languages. After all, that was one of the very design goals of Perl. The design goal of Ruby was to be better than Perl. ;-) |
I agree that there are tasks that are more easily done with PERL or Ruby,
but I don't think they can completely obviate the usefulness of awk, sed, or any of the other nice, small, quick, (obscure, obfuscated, complex) tools that have been around for N years (and with good reason). |
Yip. As I said, many tasks fit the poster child description for an awk problem. So use awk on them. But as soon as you start to struggle, stop and reach for Ruby.
|
All times are GMT -5. The time now is 11:41 AM. |