retrieving data between two strings


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers retrieving data between two strings
# 15  
Old 09-06-2012
Check thisSmilie
# 16  
Old 09-06-2012
i just want to apply a filter based on the 4th column.
# 17  
Old 09-06-2012
Quote:
Originally Posted by NareshN
i just want to apply a filter based on the 4th column.

Use below command...

Code:
START="02:00:00"
NOW="03:00:00"
awk -v ST="$START" -v NW="$NOW" '{ if ($4 >= ST && $4 <= NW ) print }' file

# 18  
Old 09-06-2012
thanks pamu,
but its not working.
i need the code something like

Code:
awk '{print $4}' filename | awk '/0[2-2]:[0-2][0-9]:[0-9][0-9]/ || /[0-0][2-2]:[0-9][0-9]:[0-9][0-9]/,/0[2-2]:[0-2][0-9]:[0-9][0-9]/' filename |  awk 'print $0'

Based on the 1st awk result, i need to search the data by using 2nd awk and to display all the records by using 3rd awk command.

Above code is just an example.

this
Code:
awk '/0[2-2]:[0-2][0-9]:[0-9][0-9]/ || /[0-0][2-2]:[0-9][0-9]:[0-9][0-9]/,/0[2-2]:[0-2][0-9]:[0-9][0-9]/'

is working fine.I just need to apply a filter.
# 19  
Old 09-06-2012
Quote:
Originally Posted by NareshN
thanks pamu,
but its not working.
i need the code something like
I am not getting what is problem Smilie

I am getting perfect here..
Code:
START="02:00:00"
NOW="03:00:00"
$ awk -v ST="$START" -v NW="$NOW" '{ if ($4 >= ST && $4 <= NW ) print }' file
Thu Sep 6 02:15:54 2012->ABCServ(603):$Id: ABCServ.c,v 1.3 2006/08/24 20:52:17 rkaps
Thu Sep 6 02:20:12 2012->ABCServ(603):$Id: ABCServ.c,v 1.3 2006/08/24 22:52:17 rkaps

If you want to change the filter just change the values for START and NOW.

Why you are forcing to use your solution..

is this a homework..?
# 20  
Old 09-06-2012
this code is already working in production env. I just want to enhance this.
Code:
awk '/0[2-2]:[0-2][0-9]:[0-9][0-9]/ || /[0-0][2-2]:[0-9][0-9]:[0-9][0-9]/,/0[2-2]:[0-2][0-9]:[0-9][0-9]/

this is just one example. Like this, there is a lot of scenairos to fetch the data between start and end date.

Last edited by NareshN; 09-06-2012 at 08:40 AM..
# 21  
Old 09-07-2012
Quote:
Originally Posted by NareshN
this code is already working in production env. I just want to enhance this.
Code:
awk '/0[2-2]:[0-2][0-9]:[0-9][0-9]/ || /[0-0][2-2]:[0-9][0-9]:[0-9][0-9]/,/0[2-2]:[0-2][0-9]:[0-9][0-9]/

this is just one example. Like this, there is a lot of scenairos to fetch the data between start and end date.
Try something like this..

For 02:00:00 to 03:00:00

Just change your range accordingly...

Here first condition captures data from 2.00 to 2.59 and second condition captures for any entries at 3.00.

Hope it helps you...Smilie

Code:
awk '$4 ~ /[0-0][2-2]:[0-9][0-9]:[0-9][0-9]/ || $4 ~ /[0-0][3-3]:[0-0][0-0]:[0-0][0-0]/  { print }' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get data from file using awk within strings.

i am having the text data file as below. Processing 1 a 111111 b c d e f Processing 2 a b 222222 c erorr d e f Processing 3 a b 3333 (1 Reply)
Discussion started by: expert
1 Replies

2. Shell Programming and Scripting

Retrieving sequence data from other file

Hello experts :cool:, I am new to programming and will need your help.. I have 2 very large files with the following format: FILE1: >MLP1019 PL4 >MLP7456 PL3 >MLP9268 PL9 >MLP6245 PL1 FILE2: >MLP1019 STNAPLQTSNTWVSYQPSMMMSLQ >MLP7456 PPYWYWNSAVMIFYVQPLSLLAVLLA >MLP9268... (2 Replies)
Discussion started by: narachaid
2 Replies

3. Shell Programming and Scripting

Retrieving data from 65th col (of each line) ?

Hello Friends, I am in situation where I have to note down few SQL queries from specific hexdump format. Here is an example (the query text starts at 65th character on each line) ---------------------- 0x000007FEB0E701C0 : 7365 6C65 6374 2063 7573 746E 6F2C 2020 select custno, ... (9 Replies)
Discussion started by: Sunusernewbie
9 Replies

4. Linux

Retrieving Data from VHD File (Virtual Machine Harddrive)

Hello, I had Gentoo installed on a Microsoft Windows Hyper-V virtual machine. The system shutdown properly but the RAID array on the drive it was on failed. We had a backup that was poorly configured and as such we didn't back up all of the data we needed. Therefore, after getting the RAID... (0 Replies)
Discussion started by: ckoeber
0 Replies

5. UNIX and Linux Applications

Retrieving data from a database and store to a file

Hi I'm using and Oracle 10g Database. I want to write a script to retrieve data from the database and store it toa file. I'm using simple sql statements such as Select * from celltable I don't know how to specify the database name etc. I have this but it doesn't work ... (1 Reply)
Discussion started by: ladyAnne
1 Replies

6. Shell Programming and Scripting

Extract and parse data between two strings

Hi , I have a billing CDR file which is separated by “!”. I need to extract and format data between the starting (“!”) and the end of the line (“1.2.1.8”). These two variables are permanent tags to show begin and end. ! TICKET NBR : 2 ! GSI : 101 ! 3100.2.112.1 24/03/2010 00:41:14 !... (3 Replies)
Discussion started by: jaygamini
3 Replies

7. Shell Programming and Scripting

Extract data between two strings

Hi , I have a billing CDR file which has repeated lines as indicated below and I need to extract data between two strings (i.e.: <?> and </?>). Eventually, map that information with the corresponding field. I'm new to unix, any help will be greatly appreciated. Gamini Input (single line): !... (3 Replies)
Discussion started by: jaygamini
3 Replies

8. Shell Programming and Scripting

Using loop reading a file,retrieving data from data base.

Hi All, I am having trouble through, I am reading the input from tab delimited file containing several records, e.g. line1 field1 field2 field3 so on.. line2 field1 field2 field3 so on.. .. .. on the basis of certain fields for each record in input file, I have to retrieve... (1 Reply)
Discussion started by: Sonu4lov
1 Replies

9. Shell Programming and Scripting

How to grab data between 2 strings ?

Hi All, I have a text file below. How do i grab all the data between "05T00NPQSMR1" and "****" using awk ? Pls note that the text lines may not be fixed and text content is dynamic. Pls help. Thanks Below is my code where $LOT_SUFFIX is my shell variable. awk '/'"$LOT_SUFFIX"'/,/blah/'... (16 Replies)
Discussion started by: Raynon
16 Replies

10. UNIX for Dummies Questions & Answers

Retrieving data

Friends, I have a data with 3 columns: 30 41 1 39 19 4 14 25 3 .... .... ..... I want to retrieve any data in the first column that is greater 15. What is the best way to do this? Thanks! (2 Replies)
Discussion started by: bobo
2 Replies
Login or Register to Ask a Question