- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- parser multiple lines
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
тАО03-07-2006 04:10 AM
тАО03-07-2006 04:10 AM
*******************************************
Unix ID:XXX
Total Views:5
content....
*******************************************
Unix ID:YYY
Total Views:12
content....
********************************************
...
I want to find whose view is greater than 10 and extract his data.
For example above, the output should look like
Unix ID:YYY
Total Views:12
content....
can awk or whatever..take multiple lines?
thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2006 05:01 AM
тАО03-07-2006 05:01 AM
SolutionGoogle: +awk +paragraph +site:itrc.hp.com
Here is how I might solve your question with a '1 liner'.
awk '/Total V/{split($0,a,":"); if (a[2] >10) {print unix}} /^\*/{a[2]=0} {if(a[2]>10){print} else {unix=$0}}' x
In details:
==> /Total V/{split($0,a,":");
If we see the line beginning with total then split using a colon or get the number in array element a[2].
==> if (a[2] >10) {print unix}}
If that array element is larger than 10, print a stashed away prior line(s).
==> /^\*/{a[2]=0}
If we see line starting with *, then indicate being done by clearing the counter.
==> {if(a[2]>10){print} else {unix=$0}}
For every line, print it if count is high, else stash away line in case it happens to become next "Unix ID"
Good luck,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2006 05:15 AM
тАО03-07-2006 05:15 AM
Re: parser multiple lines
You can use the awk construct given below. :
==============mycmds.awk=====================
$0 ~ /^Unix ID/ {
prev=$0
getline
val=z[split($NF,z,":")]
curr=$0
getline
if(val>10) {
printf("%s\n%s\n%s\n",prev,curr,$0) }
}
=============================================
Put all the above commands in a file named mycmds.awk and execute as:
# awk -f mycmds.awk
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2006 05:17 AM
тАО03-07-2006 05:17 AM
Re: parser multiple lines
This would work for you:
#!/usr/bin/perl
while (<>) {
print if $tog == 1;
$tog = 0 if m/^\*/;
next if ($id = m/Unix/);
if (m/Total Views:(\d+)/) {
if ($1 > 10) {
$tog = 1;
print $id, $_ ;
}
}
}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2006 05:22 AM
тАО03-07-2006 05:22 AM
Re: parser multiple lines
Oh, and having named my script:
# parse.pl
#!/usr/bin/perl
while (<>) {
print if $tog == 1;
$tog = 0 if m/^\*/;
next if ($id = m/Unix/);
if (m/Total Views:(\d+)/) {
if ($1 > 10) {
$tog = 1;
print $id, $_ ;
}
}
}
...run as:
./parse.pl filename
Regards!
...JRF,,,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2006 06:52 AM
тАО03-07-2006 06:52 AM
Re: parser multiple lines
let me give a try!
I assigned everyone some points!!