Find the answer to your Linux question:
Results 1 to 5 of 5
Looking for help trying to accomplish writing a script to accomplish the following. Go to a specified directory and open a log file and parse out specific information and dump ...
  1. #1
    Just Joined!
    Join Date
    Mar 2011
    Posts
    2

    Writing A Script To Parse Information From A Text File

    Looking for help trying to accomplish writing a script to accomplish the following.

    Go to a specified directory and open a log file and parse out specific information and dump it into another text file.

    Can anyone point me in the right direction?

  2. #2
    Just Joined!
    Join Date
    Apr 2011
    Posts
    5
    Something like:
    Code:
    grep "specific information" /path/to/logfile > another/text/file
    perhaps?

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    That depends a lot on what the information is that you're looking for. If you're looking for something like "Every line that contains the word 'hello'", then grep is indeed the easiest and best way, as heliumhe says.

    If, however, you want the third column of any line where the first column is a word that is present in some other file, things get more complicated. At this point, you should look into scripting languages (Bash is a simple one, and Perl, Ruby, and Python are all more advanced and complex), and some shell utilities like grep, sed, awk, and cut.

    Good luck. If you have more information, or a more specific question, feel free to post.
    DISTRO=Arch
    Registered Linux User #388732

  4. #4
    Just Joined!
    Join Date
    Mar 2011
    Posts
    2
    Both responses, SUPER Helpful thanks!

    The grep worked for what I was trying to do.

    Can either of you recommend how I would accomplish automating this to run say once a day?

    Thanks in advance!

  5. #5
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    Use cron for scheduling.

    But you might also want to have a look at
    man logwatch
    You must always face the curtain with a bow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...