- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Find a sentence, skip 5 lines, read lines 6-8
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
тАО01-13-2008 08:03 PM
тАО01-13-2008 08:03 PM
Find a sentence, skip 5 lines, read lines 6-8
I have a scenario where a shell script is required to grep and match phrase from a logfile, then skip the next few lines then grep the next subsequent lines.
And I have to display the first grep phrase plus the next subsequent lines.
For example: I want to grep if "Severity............: INFORMATION" exist, then grep from "Summary..." onwards (which is in 2-4 lines depending on the details in Summary.
Results hoped for:
"Serverity............: INFORMATION. Summary: Adapter at hardware path 0/4/1/0/4/0 : CISS: RAID SA controller is now online."
Some challenges:
1. The logfile gets appended- How can the script tell when it read the logfile last?
Event data from monitor:
Event Time..........: Thu Mar 30 11:29:50 2006
Severity............: INFORMATION
Monitor.............: dm_raid_adapter
Event #.............: 2
System..............: SERVER_NAME
Summary:
Adapter at hardware path 0/4/1/0/4/0 : CISS: RAID SA controller is now
online.
Hope some of you gurus can help me.
Thanks.
Amy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 01:04 AM
тАО01-14-2008 01:04 AM
Re: Find a sentence, skip 5 lines, read lines 6-8
What happens if there is more than one occurrence? Did you want to do it only once? Or all occurrences?
You could try:
awk -v START=$number '
/Severity............: INFORMATION/ {
if (NR <= START) next # already done
save_NR = NR
save = $0
getline; getline; getline; getline; getline
save2 = $0
getline
save3 = $0
getline
save4 = $0
print save, save2, save3, save4
}
END { print "Restart after line, save_NR" }
' file
Issues: Not sure how many lines in Summary to print?
You have to take the output of the "Restart after" to feed it back as $number.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 01:05 AM
тАО01-14-2008 01:05 AM
Re: Find a sentence, skip 5 lines, read lines 6-8
END { print "Restart after line", save_NR }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 02:45 AM
тАО01-14-2008 02:45 AM
Re: Find a sentence, skip 5 lines, read lines 6-8
I have managed to write another script. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 07:59 AM
тАО01-14-2008 07:59 AM
Re: Find a sentence, skip 5 lines, read lines 6-8
my 2 cents
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 05:44 PM
тАО01-14-2008 05:44 PM
Re: Find a sentence, skip 5 lines, read lines 6-8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2008 11:57 PM
тАО01-16-2008 11:57 PM
Re: Find a sentence, skip 5 lines, read lines 6-8
http://forums.itrc.hp.com/service/forums/helptips.do?#33