- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- command to get the phrase and next line
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
Discussions
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
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
11-08-2006 03:14 AM
11-08-2006 03:14 AM
command to get the phrase and next line
I need to pull out some information from a log file.
I have a key word which is "Start of" however I also need the line afterwards, this is the date.
I also need to pull out another key word "Done" and the previous line this time.
Example of the file
ie
Start of Log file
11:00 08/11/06
Running copy
Deleting
11:15 08/11/06
Done
The output I want is
Start of Log file
11:00 08/11/06
11:15 08/11/06
Done
I've can only manage to grep out Start Of and Done.
can someone help.
Thanks
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2006 03:33 AM
11-08-2006 03:33 AM
Re: command to get the phrase and next line
"Handy One-Liners for Sed" contains an example that prints the line before and after a regular expression:
# print 1 line of context before and after regexp, with line number
# indicating where the regexp occurred (similar to "grep -A1 -B1")
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
I'm attaching the rest of the document for future reference.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2006 03:35 AM
11-08-2006 03:35 AM
Re: command to get the phrase and next line
$>grep -e 'Start' -e ":" -e 'Done' grep.test
Start of Log file
11:00 08/11/06
11:15 08/11/06
Done
or the same result:
$>grep -e 'Start' -e "/" -e 'Done' grep.test
Start of Log file
11:00 08/11/06
11:15 08/11/06
Done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2006 03:47 AM
11-08-2006 03:47 AM
Re: command to get the phrase and next line
# perl -ne 'if (/^Start/) {print;$x=1;next};if (/^Done/) {print $hold;print};$hold=$_;if ($x==1) {print;$x=0}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2006 03:55 AM
11-08-2006 03:55 AM
Re: command to get the phrase and next line
AWK is not worse:
awk '/Start of Log file/ {getline;print}
/Done/ {print PrevLine}
{ PrevLine=$0 }' logfile
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2006 04:25 AM
11-08-2006 04:25 AM
Re: command to get the phrase and next line
# ex -s +"/^Start/,/^Start/+1 p | /^Done/-1,/^Done/ p | q!" file
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2006 04:43 AM
11-08-2006 04:43 AM
Re: command to get the phrase and next line
awk "/^Start/{print; getline; print} /^Done/ { print old; print} {old=$0}" tmp.txt
This will also print the Start and Done lines as requested.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2006 05:55 PM
11-08-2006 05:55 PM
Re: command to get the phrase and next line
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2007 08:00 PM
01-17-2007 08:00 PM
Re: command to get the phrase and next line
http://forums1.itrc.hp.com/service/forums/helptips.do?#28
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2007 09:10 PM
01-17-2007 09:10 PM
Re: command to get the phrase and next line
The awk program should typically be in single quotes, not double quotes. In particular the $0 will have problems.