- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl grep question
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
Forums
Discussions
Discussions
Forums
Discussions
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
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
04-13-2004 07:06 AM
04-13-2004 07:06 AM
The log is set up as follows:
Account Name:
User Name:
Date:
Time:
Description:
I want to be able to pull all blocks that have an account name like Unix. Is there a way in perl to say find a line with Account Name = Unix and give me all other information until the next blank line?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2004 07:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2004 07:42 AM
04-13-2004 07:42 AM
Re: Perl grep question
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2004 08:04 AM
04-13-2004 08:04 AM
Re: Perl grep question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2004 09:06 AM
04-13-2004 09:06 AM
Re: Perl grep question
Now if you need to do more than just the print, then yo may want to consider the more classical 'set flag when in range' approach:
perl -ne '$block=1 if (/^Account Name: Unix/); print if ($block); $block=0 if (/^$/); ' < your-file>
flip the print and block=0 sub commands depending on whether you want to retain the empty line or not.
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2004 02:26 AM
04-14-2004 02:26 AM
Re: Perl grep question
Account Name: schmoe
User Name: Joe Schmoe
Date: 04/14/2004
Time: 10:10
Description: Test
Account Name: doej
User Name: John Doe
Date: 04/14/2004
Time: 10:10
Description: Test
I try the following one liner and get a blank line for a return:
perl -ne 'print if /^Account Name: Unix/./^$/' /tmp/log.tmp
I then try the other one liner and get 00000 for a return:
perl -ne '$block=1 if(/^Account Name: Unix/); print ($block); $block=0 if (/^$/);' /tmp/log.tmp
I am sure I am making a very dumb mistake but as of yet I can't find it. Is my syntax wrong????
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2004 02:31 AM
04-14-2004 02:31 AM
Re: Perl grep question
How about a sed solution:
# print paragraph if it contains AAA (blank lines separate paragraphs)
# HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'
From "Handy One-Liners for Sed" (attached).
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2004 02:38 AM
04-14-2004 02:38 AM
Re: Perl grep question
Also because the Forum's HTML code (any HTML for that matter) doesn't handle whitespace well, make sure that the expected string exactly matches the input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2004 02:39 AM
04-14-2004 02:39 AM
Re: Perl grep question
That changes the expression that is needed in order for the patterns to match.
An actual data sample, of one that should match and one that should not match, would help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2004 03:51 AM
04-14-2004 03:51 AM
Re: Perl grep question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2004 04:19 AM
04-14-2004 04:19 AM
Re: Perl grep question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2004 04:23 AM
04-14-2004 04:23 AM
Re: Perl grep question
chomp;
if (/AccountName:\s+Unix/ ... /Description:/) {
print "$_\n";
}
}
forgive the spacing problem but the if statement should be on the same line.
Hopefully this is what you are looking for
Regards,
Scott Palmer