Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3273646
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:57:14+00:00 2026-05-17T18:57:14+00:00

I love Python but do not really care for AWK. For purposes of comparison

  • 0

I love Python but do not really care for AWK. For purposes of comparison (and to see how a Python-to-AWK master would do this), could someone rewrite the following Python program in AWK? Considering how short it is, some would think that the rewrite would be simple and easy for anyone with a little time.

import os

ROOT = '/Users/Zero/Documents/MyProgram.app/Contents/TempFiles'
ID = '628251 173511 223401 138276 673278 698450 629138 449040 901575'.split()

def main():
    for name in os.listdir(ROOT):
        if '.log' in name.lower():
            path = os.path.join(ROOT, name)
            if os.path.isfile(path):
                data = open(path, 'rb').read()
                for line in data.split('\r'):
                    for number in ID:
                        if number in line:
                            print line
                            break

if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:57:15+00:00Added an answer on May 17, 2026 at 6:57 pm
    BEGIN{
       id="628251 173511 223401 138276 673278 698450 629138 449040 901575"
       m=split(id,ID," ")
       for(i=1;i<ARGC;i++){
           while( (getline line<ARGV[i] ) > 0 ){
               n=split(line,LINE," ")
               for ( o=1; o<=n; o++){
                    for(num in ID){
                       if ( num == LINE[o] ){
                         print line
                       }
                    }
               }
           }
       }
    }
    

    save as myscript.awk , then

    #!/bin/bash
    ROOT = "/Users/Zero/Documents/MyProgram.app/Contents/TempFiles"
    cd $ROOT
    awk -f myscript.awk file* #do for files that start with "file"
    

    @OP,

    For text/file processing, awk doesn’t lose to Perl or Python or any others. If you (or others here thinking awk is obsoleted) are interested, go to http://awk.info. And no, awk still has its uses in the modern environment. don’t let anyone tell you otherwise

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Python and I really love the min function. >>>min([1,3,15]) 0 But
I'd love a good native Python library to write XLS, but it doesn't seem
I love how in python I can do something like: points = [] for
I love list comprehensions in Python, because they concisely represent a transformation of a
I love vim and the speed it gives me. But sometimes, my fingers are
I've started messing around with Google App Engine, writing Python. I love Visual Studio
I was wondering is learning Python and Django a hard/time consuming process for someone
There is a module I'd love to download, but it is only available in
Consider this short python list of dictionaries (first dictionary item is a string, second
I love the ease that the ASP.NET Ajax control Toolkit provides to ASP.NET developers.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.