- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Getting lines from a report - ksh
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2010 10:28 AM
тАО07-03-2010 10:28 AM
first Job has 5 lines of info, the, appears the space, the following job has only 1 line of info then
appears an space and go on ....
Report 07 Job History Listing 06/02/10
Date Time Schedule Name Elapsed CPU Status
line 1: Job:PDWH06UX #PPYHP_DWH_ECS_NACRLAN_M
line 2: 06/01/10 15:05 PDWH06UX #JOBS 1 1
line 3: 06/01/10 15:33 PDWH06UX #JOBS2 1 1
line 4: 06/01/10 15:34 PDWH06UX #JOBS3 1 1
line 5: 06/01/10 15:36 PDWH06UX #JOBS4 1 1
line 6: 06/01/10 15:37 PDWH06UX #JOBS5 1 1
line 7:
line 8: Job:PDWH06UX #PPYHP_DWH_ECS_QUL1_D
line 9: 06/01/10 06:40 PDWH06UX #PPYHP_DWH_ECS_D 1 1
line 10:
line 11: Job:PDWH06UX #PPYHP_DWH_ECS_PYJFPLOG_D
line 12: 06/01/10 06:38 PDWH06UX #PPYHP_DWH_ECS_D 1 1
line 13: 06/01/10 07:28 PDWH06UX #PPYHP_DWH_ECS_D2 1 1
line 14: 06/01/10 15:32 PDWH06UX #JOBS8 1 1
line 15:
i need to get a report as follows, first get the first line "Report 07 bla bla bla ", then to get the lline that says "Job" and getting the last line before the space ...
and the get again the line which says "job" and then to get the line before the space as follows
Report 07 Job History Listing 06/02/10
Date Schedule Name Elapsed
line 1: Job:PDWH06UX #PPYHP_DWH_ECS_NACRLAN_M
line 6: 06/01/10 PDWH06UX #JOBS5
line 7:(space)
line 8: Job:PDWH06UX #PPYHP_DWH_ECS_QUL1_D
line 9: 06/01/10 PDWH06UX #PPYHP_DWH_ECS_D
line 10: (space)
line 11: Job:PDWH06UX #PPYHP_DWH_ECS_PYJFPLOG_D
line 14: 06/01/10 PDWH06UX #JOBS8
Thanks in advance.
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2010 10:51 AM
тАО07-03-2010 10:51 AM
Re: Getting lines from a report - ksh
Are you getting paid to do this?
Have you considered getting a book, or taking
a class, to learn how to write a computer
program?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2010 11:21 AM
тАО07-03-2010 11:21 AM
Re: Getting lines from a report - ksh
I have done shells in ksh , i have used a little bit the awk but i do not know how to evaluate "if there is an space, keep previous line in a variable"
can you help me with this:
"if there is an space, keep previous line in a variable"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2010 11:22 AM
тАО07-03-2010 11:22 AM
SolutionManuales...
You about this awk 'one liner' or mini program:
awk '(NR < 3)
/^Job:/ { job = $0 }
!NF && job != "" { print; print job; print last; job="" }
{ last = $1 " " $3 " " $4}' report.txt
In slo mo...
(NR < 3) : true for the first 2 lines. No action specified, so take default action is to print the input line.
/^Job:/ { job = $0 } : If the line starts with Job: then save it in variable job
!NF && job != "" { print; print job; print last; job="" } : If there are NO fields on the line, and the variable job is not empty, then print a blank line, print job, and print a variable last which will hold data from the last non-blank line.
{ last = $1 " " $3 " " $4} : any time, unconditionally, stash field 1, 3 and 4 in a variable last, just in case it really is the last line.
Enjoy,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2010 11:35 AM
тАО07-03-2010 11:35 AM
Re: Getting lines from a report - ksh
The test for job != "" and the clearing of job after print is in order to protect against additional blank lines or random blob of text in the report.
if the input is exactly as you describe, then this will be enough:
$ awk 'NR < 3; /^Job:/ {print "\n" $0}; !NF {print last} { last = $0}' report
Report 07 Job History Listing 06/02/10
Date Time Schedule Name Elapsed CPU Status
Job:PDWH06UX #PPYHP_DWH_ECS_NACRLAN_M
06/01/10 15:37 PDWH06UX #JOBS5 1 1
Job:PDWH06UX #PPYHP_DWH_ECS_QUL1_D
06/01/10 06:40 PDWH06UX #PPYHP_DWH_ECS_D 1 1
Job:PDWH06UX #PPYHP_DWH_ECS_PYJFPLOG_D
06/01/10 15:32 PDWH06UX #JOBS8 1 1
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2010 11:41 AM
тАО07-03-2010 11:41 AM
Re: Getting lines from a report - ksh
let me try right now, let me test it .... :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2010 12:10 PM
тАО07-03-2010 12:10 PM
Re: Getting lines from a report - ksh
i was thinking in using a "for" to go evaluating line per line but i see here that i have to study more about AWK ..
really thanks again !!!! :) IT worked successfully :).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2010 07:53 AM
тАО07-04-2010 07:53 AM
Re: Getting lines from a report - ksh
Here's another way:
# perl -00 -ne '/^Report/ and print,next;/(^Job.+?$)(.*)(^\d.+$)/sm and print $1,"\n",$3' file
This reads "paragraphs" of data at a time (-00). If a paragraph begins wth "Report", print it in its entirety. If a paragraph begins with "Job", then capture the string until a newline in $1 and don't be greedy about it; grab zero or more characters in $2; and lastly stuff a line that begins with a digit (\d) into $3. If we can make such a match, print what we captured in $1 and $3.
Since we don't care about $2 (the lines beginning with a digit that aren't the last one in a group) we could/should skip their capture. To do this we make a slight change and tell the regular expression engine that we don't want to capture (?:) the second group ().
# perl -00 -ne '/^Report/ and print,next;/(^Job.+?$)(?:.*)(^\d.+$)/sm and print $1,"\n",$2' file
Regards!
...JRF...