- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to search a few lines from a file?
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
01-24-2002 06:52 PM
01-24-2002 06:52 PM
can anybody tell me how to print out from a text file 5 lines starting from the first occurence of one particular 'mystring'?
It seems sed -n '/mystring/,+5p' myfile can't work.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2002 06:59 PM
01-24-2002 06:59 PM
Re: How to search a few lines from a file?
>> can anybody tell me how to print out from a text file 5 lines starting from the first occurence of one particular 'mystring'?
# tail +`cat -n file | grep mystring | awk '{print $1}'` | head -5
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2002 08:10 PM
01-24-2002 08:10 PM
Re: How to search a few lines from a file?
"tail +$(grep -n "^DMS" listener.ora|awk -F: '{print $1}'|head -1) listener.ora|head -5"
Actually I am searching for host name/IP address in Oracle listener.ora file given Database name "ORACLE_SID". Is there better way to do that? Can I use sed ?
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2002 08:17 PM
01-24-2002 08:17 PM
Re: How to search a few lines from a file?
I have now included the head -1 to take core of multiple occurrences of mystring.
# cat -n file | grep mystring | awk '{print $1}' | head -1
This greps for the line no. of the first line containing the string.
# tail +`cat -n file | grep mystring | awk '{print $1}' | head -1`
This tails from the line containing the string until the end of the file.
# tail +`cat -n file | grep mystring | awk '{print $1}' | head -1` | head -5
This extracts the 1st 5 lines from the line containing the string until the end of the file.
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 01:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 01:44 AM
01-25-2002 01:44 AM
Re: How to search a few lines from a file?
Here's one way with sed:
sed -n '/string/{
N
N
N
N
p
}' filename
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2002 12:57 AM
02-04-2002 12:57 AM
Re: How to search a few lines from a file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2002 06:18 PM
02-05-2002 06:18 PM
Re: How to search a few lines from a file?
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2003 09:48 PM
05-19-2003 09:48 PM
Re: How to search a few lines from a file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2003 09:50 PM
05-19-2003 09:50 PM
Re: How to search a few lines from a file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 06:28 AM
05-20-2003 06:28 AM
Re: How to search a few lines from a file?
sed -n '/string/{
N
N
N
N
p
q
}' filename
This will then quit after the first group is printed.
HTH
-- Rod Hills