Capture a block of data


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Capture a block of data
# 1  
Old 05-25-2012
Capture a block of data

Hi,
I was trying a script to cature all data between 12-05-09 06:00:00 to 12-05-09 23:59:59 from a huge file. (i.e. Skip all data between 00:00:00 to 05:59:59)
Code:
TOKEN-1 12-05-09 00:00:00 MAIPR no_OMDB_key #000995 >
..
..
..
TOKEN-1 12-05-09 06:00:00 TRUNK 358 #04988 >
..
..
TOKEN-1 12-05-09 23:59:59 SMCONF 599 #16721 >

Please suggest how it can be performed.

Script I was trying was as under :-

Code:
gawk -v search="12-05-09 06:00:00" '
    /12-05-09 06:00:00/,/12-05-09 23:59:59/ { 
       block = (block ? block ORS : "") $0;
    }
    /12-05-09 23:59:59/ { 
       if (block ~ search) 
          print block;
       block = "\n";
    } ' <myfile>

It is not working anyways. Kindly help.

Thanks..

Last edited by Franklin52; 05-27-2012 at 08:12 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 05-25-2012
You can compare 24-hour HH:MM:SS times with < > = since they sort alphabetically. So you just match the day and time, and use that to turn on and off a variable. That variable decides whether it should print the lines that come after.

Code:
$ awk '/^TOKEN-/ { P=0; if(($2==DATE)&&($3>=MINTIME)&&($3<=MAXTIME)) P=1 } P' DATE="12-05-09" MINTIME="06:00:00" MAXTIME="23:59:59" data

TOKEN-1 12-05-09 06:00:00 TRUNK 358 #04988 >
..
..
TOKEN-1 12-05-09 23:59:59 SMCONF 599 #16721 >

$


Last edited by Corona688; 05-25-2012 at 12:42 PM.. Reason: bugfix
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 05-25-2012
Are those dates YY-MM-DD, incidentally? That'd sort alphabetically too, and you could just check if(($2" "$3 >= MINDATE) && ($2" "$3 <= MAXDATE)) with MINDATE and MAXDATE like YY-MM-DD HH:MM:SS. That'd let you select across multiple days.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to capture last 15mins data logged from server.log file?

Below is Script to scan the errorlist file (errorlist file includes a list of errors) with sererv.log file (sererv.log file should contain data of recent 15mins ) but my requirement is I should get the recent logs i.e. cmd to capture only recent 15mins data logged from sererv.log file then scan... (3 Replies)
Discussion started by: manohar2013
3 Replies

2. Shell Programming and Scripting

Unable to print block of data

Hi All, Iam unable to print the below block and getting the error.Can anyone please help me in this. Input Data eaits001z$ echo "-------LINENO_JOBID_VAL--------${LINENO_JOBID_VAL}---" -------LINENO_JOBID_VAL--------58167|253473 58169|253473 58171|253473 58179|253473 58180|253473 58181|257311... (9 Replies)
Discussion started by: cskumar
9 Replies

3. Shell Programming and Scripting

Capture the data in Linux .While doing load test.

Hi All, I am trying to capture the data in linux .While doing load test. is there's any sample script please help me. Linux test4 2.6.18-308.8.1.el5 #1 SMP Fri May 4 16:43:02 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux Thanks, (5 Replies)
Discussion started by: sam1226
5 Replies

4. Shell Programming and Scripting

How to compare data from 2 zip files and capture the new records from file2 to a new file

I have 2 zip files which have about 20 million records in each file. file 2 will have additional records than file 1. I want to compare the records in both the files and capture the new records from file 2 into another file file3. Please help me with a command/script which provides me the desired... (8 Replies)
Discussion started by: koneru
8 Replies

5. UNIX for Advanced & Expert Users

capture data from matched string/line

Hi, I have a query as follows : suppose I am matching a string in a file say "start from here" and I want to pick up 'n' number of lines () from the matched string. Is there any way to do that ? 1) going forward I want to do this for every match for the above string 2) or limit this to... (2 Replies)
Discussion started by: sumoka
2 Replies

6. IP Networking

Creating a printer emulator to capture PDL/PCL data coming in on port 9100.

I have a number of Windows CE operator terminals. They have facility to print alarms/messages to ... aser or Inkjet (so they're using PCL). USB or IP. IP connection takes just the IP address. Question How could I create a service or daemon on a server to capture all this data?... (7 Replies)
Discussion started by: transistor
7 Replies

7. Shell Programming and Scripting

Capture two set of data to same line...simple

I would like to capture output from two commands to a test file on the same line... I want to get a file with all Applications and the Version of it...here are the two commands I use to get the output. To get Application list I use ls -1 /Applications/ |grep .app >>... (3 Replies)
Discussion started by: elbombillo
3 Replies

8. Shell Programming and Scripting

Capture data in a file

How to capture the rows in a file after executing the store procedure using the perl scripts? (0 Replies)
Discussion started by: vinay123
0 Replies

9. UNIX for Dummies Questions & Answers

Howto capture data from rs232port andpull data into oracle database-9i automatically

Hi, i willbe very much grateful to u if u help me out.. if i simply connect pbx machine to printer by serial port RS232 then we find this view: But i want to capture this data into database automatically when the pbx is running.The table in database will contain similar to this view inthe... (1 Reply)
Discussion started by: boss
1 Replies

10. Shell Programming and Scripting

Capture POST data

Is it possible to capture data posted from a Web Form?? I mean when data in the form on a webpage is send via POST method and not GET method. Can it be captured! (1 Reply)
Discussion started by: azmathshaikh
1 Replies
Login or Register to Ask a Question