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 788795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:25:26+00:00 2026-05-14T21:25:26+00:00

I am using this function in my code to return the strings i want

  • 0

I am using this function in my code to return the strings i want from reading the log file, I want to grep the “exim” process and return the results, but running the code gives no error, but the output is limited to three lines, how can i just get the output only related to exim process..

#output:
    {'date': '13', 'process': 'syslogd', 'time': '06:27:33', 'month': 'May'}
    {'date': '13', 'process': 'exim[23168]:', 'time': '06:27:33', 'month': 'May'}
    {'May': ['syslogd']}


#function:    
def generate_log_report(logfile):
    report_dict = {}
    for line in logfile:
        line_dict = dictify_logline(line)
        print line_dict
        try:
            month = line_dict['month']
            date = line_dict['date']
            time = line_dict['time']
            #process = line_dict['process']
            if "exim" in line_dict['process']:
                process = line_dict['process']  
                break
            else:
                process = line_dict['process']      
        except ValueError:
            continue
        report_dict.setdefault(month, []).append(process)
    return report_dict
  • 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-14T21:25:26+00:00Added an answer on May 14, 2026 at 9:25 pm

    i changed the code to this, but it gives me just one line as output??? anything missing…

    #!/usr/bin/env python
    
    import sys
    
    def generate_log_report(logfile):
            for line in logfile:
                    line_split = line.split()
                    list = [line_split[0], line_split[1], line_split[2], line_split[4]]
                    if "exim" in list[3]:
                            l = [line_split[0], line_split[1], line_split[2], line_split[4]]
                    else:
                            li = [line_split[0], line_split[1], line_split[2], line_split[4]]
            return l
    
    
    if __name__ == "__main__":
            if not len(sys.argv) > 1:
                    print __doc__
                    sys.exit(1)
            infile_name = sys.argv[1]
            try:
                    infile = open(infile_name, "r")
            except IOError:
                    print "you must specify a valid file"
                    print __doc__
                    sys.exit(1)
            log_report = generate_log_report(infile)
            print log_report
            infile.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 501k
  • Answers 501k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are truly not so many ressources out there. Here… May 16, 2026 at 2:23 pm
  • Editorial Team
    Editorial Team added an answer Just write down Go after the command will work for… May 16, 2026 at 2:23 pm
  • Editorial Team
    Editorial Team added an answer All the logger levels below root inherit the appenders from… May 16, 2026 at 2:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a source container of strings I want to remove any strings from
I'm using this code: $newFilter = getNewFilter(); $fieldDropdown = getFieldDropdown(fieldData.field); $newFilter.append($fieldDropdown); $typeDropdown = getTypeDropdown($fieldDropdown.data('zenfilter').fieldId,
I have some data, yes, data. This data came from a MySQL query and
We would like to enumerate all strings in a resource file in .NET (resx
The average man does not want to be free. He simply wants to be
Boost comes with an example file in boost_1_41_0\libs\function_types\example called interpreter.hpp and interpreter_example.hpp I am
I am new to jquery. I am trying to parse xml string using jquery.
I am trying to create a small function that returns the number of spaces
I want to check if a variable called $smth is blank (I mean empty
I've a string 01-India . I want to split on '-' and get only

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.