Operating System - HP-UX
1833757 Members
2606 Online
110063 Solutions
New Discussion

Re: Extracting lines from a canned report

 
SOLVED
Go to solution
Belinda Dermody
Super Advisor

Extracting lines from a canned report

We have this canned report running daily but a manager only wants certain data from it. The key lines are
Application : Smart
Call List : XYZABC

Totl Calls:
Avg time

Have attached a sample of the orginal report best to set you terminal to 132 characters. Can any of you guru's come up with a way to extract this information.
5 REPLIES 5
Pete Randall
Outstanding Contributor

Re: Extracting lines from a canned report

James,

Take a look at the attached "Handy One-liners for Sed" (courtesy of Princess Paula). You'll find a section "# print section of file between two regular expressions (inclusive)"
That should do what you ask.


Pete


Pete
Leif Halvarsson_2
Honored Contributor

Re: Extracting lines from a canned report

Hi,
Or, if you prefer awk you can try with a reursive function:

function aaa()
{
getline x
if (x !~ /Totl/)
{
print x
aaa()
}
else
print x
}

/Application/ { print; aaa() }
Belinda Dermody
Super Advisor

Re: Extracting lines from a canned report

Leif, thanks for the response, how would I set up the awk statement to do your example, I just do the basic with awk, awk '{print ....} and other small awk stuff.
Mark Grant
Honored Contributor

Re: Extracting lines from a canned report

I know this looks nasty but...

perl -n -e "next if not /Call List/;while(<>){exit if /Totl Calls/;print;}" testfile
Never preceed any demonstration with anything more predictive than "watch this"
Graham Cameron_1
Honored Contributor
Solution

Re: Extracting lines from a canned report

Couldn't see any attachment, but if all you want is lines beginning with "Application", lines "Call List" to "Totl Calls", and likes beginning "Avg time", then it's trivial awk.
--
awk '
/^Application/
/^Call List/,/^Totl Calls/
/^Avg time/
' cannedfile
--
Isn't it ?
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.