find 2 line numbers, grab text in between


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find 2 line numbers, grab text in between
# 1  
Old 09-26-2006
find 2 line numbers, grab text in between

hi, i have a large text file that I just want to extract the important
information from. It will be a random number of lines but between two specific
line numbers/markers.

I was thinking I could get the line number for the first marker:
Tablespace Percent Total Free

Then get the line number for the second marker:
Tablespace Free Space Avg Fragmentation

Now all I would need to do is print out the text between the two lines
(including the 1st marker but not the second):
print 1st_marker_line# --> 2nd_marker_line#

I am pretty sure I can do this with awk but not sure how.
Thanks for your help!

Sample text:
PHP Code:
09/25/06      SPCCHK Tablespace Percent Total Free Values on SWB
                                                                   
%chg Days
Tablespace                                                  Today since till
   Name           09
/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest zero
----------------- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
BDR_DATA           89.5  89.5  89.4  89.4  89.4  89.3  89.3  89.1   -.2
SYSAUX             71.0  70.5  70.0  71.5  71.1  70.6  70.0  71.4   1.4
SYSTEM             22.7  22.7  22.7  22.7  22.7  22.6  22.2  22.2    .0  297
UNDOTBS1           21.8  21.8  22.5  31.0  30.8  29.8  29.9  30.9   1.0

09
/25/06  SPCCHK Tablespace Free Space Avg Fragmentation Pct on SWB

Fragmentation Pct is calculated by dividing the number of data files 
for a
 tablespace by the number of different chunks of free space within those 
data files
.  The lower the numberthe more fragmented your free space is.

                                                                   %
chg
Tablespace                                                  Today since
   Name           09
/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest
----------------- ----- ----- ----- ----- ----- ----- ----- ----- -----
SYSAUX             16.7  20.0  16.7    .5    .6    .8   2.3   1.0  -1.3
UNDOTBS1             .3    .3    .3    .2    .2    .2    .3    .3    .0

etc
etcetc

this is all I want printed out (or sent to to a file or whatever):
PHP Code:
09/25/06      SPCCHK Tablespace Percent Total Free Values on SWB
                                                                   
%chg Days
Tablespace                                                  Today since till
   Name           09
/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest zero
----------------- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
BDR_DATA           89.5  89.5  89.4  89.4  89.4  89.3  89.3  89.1   -.2
SYSAUX             71.0  70.5  70.0  71.5  71.1  70.6  70.0  71.4   1.4
SYSTEM             22.7  22.7  22.7  22.7  22.7  22.6  22.2  22.2    .0  297
UNDOTBS1           21.8  21.8  22.5  31.0  30.8  29.8  29.9  30.9   1.0 
# 2  
Old 09-26-2006
Perhaps this is what you want:
Code:
#!/bin/bash

TOK1="SPCCHK - Tablespace Percent Total Free Values"
TOK2="SPCCHK - Tablespace Free Space Avg Fragmentation"

INTERESTING=no
while read l; do
   TXT1=$(echo $l | grep "$TOK1")
   TXT2=$(echo $l | grep "$TOK2")
   if [[ "$TXT1" != "" ]]; then
      INTERESTING=yes
   elif [[ "$TXT2" != "" ]]; then
      INTERESTING=no
   fi
   if [[ "$INTERESTING" == "yes" ]]; then
      echo "$l"
   fi
done < ./input_file.txt

Script for bash, and probably for ksh. Needs that "./input_file.txt" exists.

Regards.
# 3  
Old 09-26-2006
Code:
sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/ p" file | sed "$ d"

# 4  
Old 09-26-2006
something to start with:

nawk -v pat='Tablespace Percent Total Free' -f duck.awk myReportFile.txt

duck.awk:
Code:
BEGIN {
   RS=FS=""
}
$1 ~ pat

# 5  
Old 09-26-2006
Code:
sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/{ /Tablespace Free Space Avg Fragmentation/!p; }" file

# 6  
Old 09-26-2006
thanks for the quick responses.

Also, what if there is more than one block (same rules) within the same filename that I need to extract?
So there would be 2-3 sets of markers possibly.
# 7  
Old 09-26-2006
If you have same kind of markers then you will get all those blocks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find duplicates in file with line numbers

Hello All, This is a noob question. I tried searching for the answer but the answer found did not help me . I have a file that can have duplicates. 100 200 300 400 100 150 the number 100 is duplicated twice. I want to find the duplicate along with the line number. expected... (4 Replies)
Discussion started by: vatigers
4 Replies

2. Shell Programming and Scripting

Grab text after pattern on the same line

data: 8iW5iPACIb5fafafEU24f3EOOjpakx6VwxBX+NafafxJMWX8iW5iPACIb5fafafEU24f3EOOjpakx6VwxBX+NafafxJMWX8iW5i PACIb5fafafEU24f3EOOjpakx6VwxBX+NafafxJMWX8iW5iPACIb5fafafEU24f3EOOjpakx6VwxBX+ 8nwR15UzfeZafaf2bGr8akx6VwxBX+NafafxJMWX8iW5iPACIb5fafafEU24f3EOOjp lVpOoMLXJ ... (19 Replies)
Discussion started by: SkySmart
19 Replies

3. Shell Programming and Scripting

How to add line numbers (multiples of 5: 0,5,10,15,20) to a text file?

Hi, I need to number the lines in my text file. I know how to do this with standard numbering (1,2,3,4, etc) but I need to count in multiples of 5, beginning 0,5,10,15... example existing file: abcd efg hijklm nopqrs desired output 0 abcd 5 efg 10 hijklm 15 ... (11 Replies)
Discussion started by: livbaddeley
11 Replies

4. Shell Programming and Scripting

How Select numbers from a line of text, and remove leading spaces?

I have a text file with a line of text that contains numbers and text formatted into groups. I need to extract the number that can be either 1,2 or 3 digits long. Then write it to a variable, but i need to remove any leading spaces in the number first. I can get the numbers out but how to remove... (12 Replies)
Discussion started by: kcpoole
12 Replies

5. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

How to find numbers in text file?

Hi I have a text file with rows like this: 7 Herman ASI-40 Jungle (L) Blueprint (L) Weapon Herman ASI-40 Jungle (L) 215.00 57 65.21 114.41 and 9 Herman CAP-505 (L) Blueprint (L) Weapon Herman CAP-505 (L) 220.00 46.84 49.1 104.82 and 2 ClericDagger 1C blueprint Melee - Shortblade... (2 Replies)
Discussion started by: pesa
2 Replies

7. Shell Programming and Scripting

How to find the matched numbers between 2 text file using perl program??

hi dudes, I nee you kind assistance, I have to find the matched numbers from 2 text files and output of matched numbers should be in another text file.. I do have text files like this , for example File 1 787 665*5-p 5454 545-p 445-p 5454*-p File 2 5455 787 445-p 4356 2445 144 ... (3 Replies)
Discussion started by: sureshraj
3 Replies

8. Shell Programming and Scripting

Grepping text by providing line numbers.

Dear Friends, I have a flat file from which I want to grep line no. 7,10, 19 to 35, 37. How can it be done? Thank you in advance Anushree (6 Replies)
Discussion started by: anushree.a
6 Replies

9. Shell Programming and Scripting

how to add line numbers in text file

Hi all How to add line numbers in text file.. ex abcd cdef result 1. abcd 2. cdef thx in advance (4 Replies)
Discussion started by: suryanarayana
4 Replies

10. Shell Programming and Scripting

how to print out line numbers of a text file?

i have this text file name test.txt which contain : aaaaa bbb iiiiiiiiiiiii ccf ddaaa ddd and i need a script that can print out the line numbers using a while loop.. so when the script is run..it will have this: 1 2 3 any ideas? :) thanks guys (4 Replies)
Discussion started by: forevercalz
4 Replies
Login or Register to Ask a Question