Sponsored Content
Top Forums UNIX for Advanced & Expert Users Get the first occurence between two patterns Post 302892227 by rpm120 on Tuesday 11th of March 2014 02:27:10 PM
Old 03-11-2014
Lightbulb Get the first occurence between two patterns

I have an output file which gives me the timely status of a server.

Sample file:

Code:
March 11 2014

21:10,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
21:05,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
21:00,   1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
20:55,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
20:50,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
.
.
.
00:00,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...

March 10 2014

21:10,    11,    22,    33,    44,    55,    66,    77,    88,    99,    xx,    yy,    zz...
21:05,    11,    22,    33,    44,    55,    66,    77,    88,    99,    xx,    yy,    zz...
21:00,    11,    22,    33,    44,    55,    66,    77,    88,    99,    xx,    yy,    zz...
20:55,    11,    22,    33,    44,    55,    66,    77,    88,    99,    xx,    yy,    zz...
20:50,    11,    22,    33,    44,    55,    66,    77,    88,    99,    xx,    yy,    zz...
.
.
.
00:00,    11,    22,    33,    44,    55,    66,    77,    88,    99,    xx,    yy,    zz...

March 09 2014

21:10,    123,    221,    331,    441,    551,    661,    771,    881,    991,    xxx,    yyy,    zzz...
21:05,    123,    221,    331,    441,    551,    661,    771,    881,    991,    xxx,    yyy,    zzz...
21:00,    123,    221,    331,    441,    551,    661,    771,    881,    991,    xxx,    yyy,    zzz...
20:55,    123,    221,    331,    441,    551,    661,    771,    881,    991,    xxx,    yyy,    zzz...
20:50,    123,    221,    331,    441,    551,    661,    771,    881,    991,    xxx,    yyy,    zzz...
.
.
.
00:00,    123,    221,    331,    441,    551,    661,    771,    881,    991,    xxx,    yyy,    zzz...

I need to get the first occurrence or sequence between the two patterns i.e "21:10" & "00:00" (time stamps)


Desired output


Code:
21:10,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
21:05,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
21:00,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
20:55,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
20:50,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...
.
.
.
00:00,    1,    2,    3,    4,    5,    6,    7,    8,    9,    x,    y,    z...

Hope I m clear with the problem statement .... Please help...
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

First Occurence

Hi, This is the format of the file that i have StartDate:10/01/06 EndDate :10/02/06 Cno Ccode 1 10 2 11 StartDate:10/03/06 EndDate :10/04/06 Cno Ccode 2 13 4 12 StartDate:10/01/06 EndDate :10/02/06 (5 Replies)
Discussion started by: kkm_job
5 Replies

2. UNIX for Dummies Questions & Answers

First occurence from grep

Hi , supoose i have a file in which a word is repeated so many times. I just want the firts occurence of that word through grep and it should not go to the next one means get the first occurence and stop there. Suggest me some solutions. Thanks Namish (10 Replies)
Discussion started by: namishtiwari
10 Replies

3. Shell Programming and Scripting

Searching patterns in 1 file and deleting all lines with those patterns in 2nd file

Hi Gurus, I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
Discussion started by: toms
4 Replies

4. Shell Programming and Scripting

How to get line after occurence of sequence of patterns

In the past I needed a help with the problem how to search for pattern after the occurence of another pattern which is described in this thread: https://www.unix.com/shell-programmin...-pattern1.html Now I would need something quite similar, only the pattern which is to be searched must be... (3 Replies)
Discussion started by: sameucho
3 Replies

5. Shell Programming and Scripting

Retrieve lines that match any occurence in a list of patterns

I have two files. The first containing a header and six columns of data. Example file 1: Number SNP ID dbSNP RS ID Chromosome Result_Call Physical Position 787066 SNP_A-8575395 RS6650104 1 NOCALL 564477 786872 SNP_A-8575125 RS10458597 1 AA ... (13 Replies)
Discussion started by: Selftaught
13 Replies

6. Shell Programming and Scripting

sed print between 2 patterns only last occurence

Hi, I have a file, which contains the following log data. I am trying to print fromt he file the following data: I have tried using sed, but I am getting from the first pattern Thanks for your help. (5 Replies)
Discussion started by: sol_nov
5 Replies

7. Shell Programming and Scripting

Print between patterns - first occurence, second occurence etc

I have a file # cat asasas AAAAAA 11 22 33 44 BBBBB NILNILNIL AAAAAA 22 33 44 55 66 77 88 BBBBB NILNILNIL (2 Replies)
Discussion started by: anil510
2 Replies

8. Shell Programming and Scripting

Grab nth occurence in between two patterns using awk or sed

Hi , I have an issue where I want to parse through the output from a file and I want to grab the nth occurrence of text in between two patterns preferably using awk or sed ! TICKET NBR : 1 !GSI : 102 ! 3100.2.112.1 11/06/2013 15:56:29 ! 3100.2.22.3 98 ! 3100.2.134.2... (8 Replies)
Discussion started by: OTNA
8 Replies

9. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

10. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies
SLEEP(1)						    BSD General Commands Manual 						  SLEEP(1)

NAME
sleep -- suspend execution for an interval of time SYNOPSIS
sleep seconds DESCRIPTION
The sleep command suspends execution for a minimum of seconds. If the sleep command receives a signal, it takes the standard action. IMPLEMENTATION NOTES
The SIGALRM signal is not handled specially by this implementation. The sleep command will accept and honor a non-integer number of specified seconds (with a '.' character as a decimal point). This is a non- portable extension, and its use will nearly guarantee that a shell script will not execute properly on another system. EXAMPLES
To schedule the execution of a command for x number seconds later (with csh(1)): (sleep 1800; sh command_file >& errors)& This incantation would wait a half hour before running the script command_file. (See the at(1) utility.) To reiteratively run a command (with the csh(1)): while (1) if (! -r zzz.rawdata) then sleep 300 else foreach i (`ls *.rawdata`) sleep 70 awk -f collapse_data $i >> results end break endif end The scenario for a script such as this might be: a program currently running is taking longer than expected to process a series of files, and it would be nice to have another program start processing the files created by the first program as soon as it is finished (when zzz.rawdata is created). The script checks every five minutes for the file zzz.rawdata, when the file is found, then another portion processing is done courteously by sleeping for 70 seconds in between each awk job. DIAGNOSTICS
The sleep utility exits 0 on success, and >0 if an error occurs. SEE ALSO
nanosleep(2), sleep(3) STANDARDS
The sleep command is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. HISTORY
A sleep command appeared in Version 4 AT&T UNIX. BSD
April 18, 1994 BSD
All times are GMT -4. The time now is 06:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy