![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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:
this is all I want printed out (or sent to to a file or whatever): PHP Code:
__________________
- The_Duck |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
Regards. |
|
#3
|
|||
|
|||
|
Code:
sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/ p" file | sed "$ d" |
|
#4
|
||||
|
||||
|
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
|
|||
|
|||
|
Code:
sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/{ /Tablespace Free Space Avg Fragmentation/!p; }" file
|
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
If you have same kind of markers then you will get all those blocks
|
|||
| Google The UNIX and Linux Forums |