If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Shell Command to Extract Data

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-04, 21:39
malinut89 malinut89 is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
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
Reply With Quote
  #2 (permalink)  
Old 01-27-04, 03:40
oluoch oluoch is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 01-27-04, 06:09
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On