30 pts.
 Help on korn shell (RedHat)
I have a file like that: ... Title 1     Abcdef     Ghijklm     Nopqrst     ... Title 2      Abcdef      Ghijkllm      Nopqrst      ... ... Under each block (Title) number of line could be between 0 and > 100 _________________________________________________________________ I'd like to know using script korn sheel how to keep only all lines between each Title?

Software/Hardware used:
Linux Red Hat
ASKED: August 19, 2010  12:44 PM
UPDATED: August 23, 2010  8:50 AM

Answer Wiki:
I assume, you need some commands to embed into a korn shell script to get rid of title line... If you want to keep all "non-title" lines, just use: grep -v '^Title [0-9]*$' filename If you want to extract a specific "chapter", you can use a combination of grep, sed, head, and tail: grep -n '^Title [0-9]*$' filename > index then, assuming you need chapter 12 : grep -A 1 '^Title 12$' index | sed 's/:.*$//' and you will have two lines with indexes of chapters 12 and 13 , which can be put into variables $index12 and $index13 and reused by tail and head: tail +$[$index12+1] filename | head -$[$index13 - $index12 -1] which will output the contents of chapter 12 without Title... headings. Unfortunately, I'm not familiar with korn shell syntax to assist you with putting output in variables and passing the required chapter number from commandline, but can assure you this works perfectly in bash script using $1 for passing the script argument and back-quotes ( `...` , $(...) ) for capturing the grep | sed output. If you are interested in bash script - feel free to write back, otherwise make some research in ksh capabilities and syntax. Good luck,
Last Wiki Answer Submitted:  August 20, 2010  1:52 pm  by  petkoa   3,120 pts.
All Answer Wiki Contributors:  petkoa   3,120 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Like that, I only have line Title N because, the content of index is Title N
What I need is to have the content of each Title (All lines between each Title) and that, Title by Title.

Thank for You help.

 30 pts.