The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to grab the value of field before the line reached ahjiefreak Shell Programming and Scripting 3 03-28-2008 02:59 AM
grab the line using awk cdfd123 Shell Programming and Scripting 1 10-10-2007 05:21 AM
grab next consecutive line or lines wisher115 Shell Programming and Scripting 1 12-07-2006 05:01 AM
how to print out line numbers of a text file? forevercalz Shell Programming and Scripting 4 12-12-2005 02:04 AM
add line numbers esham Shell Programming and Scripting 4 03-07-2005 07:46 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-26-2006
Registered User
 

Join Date: Feb 2004
Posts: 16
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 
__________________
- The_Duck
Reply With Quote
Forum Sponsor
  #2  
Old 09-26-2006
grial's Avatar
El UNIX es como un toro
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
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.
Reply With Quote
  #3  
Old 09-26-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/ p" file | sed "$ d"
Reply With Quote
  #4  
Old 09-26-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,014
something to start with:

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

duck.awk:
Code:
BEGIN {
   RS=FS=""
}
$1 ~ pat
Reply With Quote
  #5  
Old 09-26-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/{ /Tablespace Free Space Avg Fragmentation/!p; }" file
Reply With Quote
  #6  
Old 09-26-2006
Registered User
 

Join Date: Feb 2004
Posts: 16
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.
__________________
- The_Duck
Reply With Quote
  #7  
Old 09-26-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
If you have same kind of markers then you will get all those blocks
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0