Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    4

    Unanswered: Shell Command to Extract Data

    Hi,

    I'm looking for a simple shell command to extract data from a file. For example, a portion of my file may look like:

    12:00:00 AM 0.83 0.27
    12:15:00 AM 0.82 0.27
    12:30:00 AM 0.81 0.27
    12:45:00 AM 0.82 0.27
    1:00:00 AM 0.79 0.27
    1:15:00 AM 0.74 0.27
    1:30:00 AM 0.77 0.27
    1:45:00 AM 0.76 0.27
    2:00:00 AM 0.68 0.27
    2:15:00 AM 0.67 0.27

    Now, instead of using the data from every 15 minutes, I'd rather extract data from every hour on the hour. For the above sample, this would yield:

    12:00:00 AM 0.83 0.27
    1:00:00 AM 0.79 0.27
    2:00:00 AM 0.68 0.27

    Considering I have massive files to deal with, I cannot simply edit these manually. I'm hoping there's any easy shell command(s) to be used for such a circumstance. Thank you in advance!

    M89

  2. #2
    Join Date
    Jan 2004
    Posts
    15
    Hi, I suggest you use the awk utility to solve your problem. Here is a useful script that would help you.


    #! /bin/sh

    filename=$1

    awk '/:00:00/' $filename | awk '{print $0}' > newfile

    echo Done



    Regards J. Oluoch
    Nairobi, Kenya

  3. #3
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    [QUOTE
    awk '/:00:00/' $filename | awk '{print $0}' > newfile
    [/QUOTE]

    Or even...

    awk '$1 ~ /:00:00/ {print $0}' $filename > newfile

Posting Permissions

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