- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Search between two 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
тАО07-21-2009 06:31 AM
тАО07-21-2009 06:31 AM
I have a large file and want to display the data between two lines but not the lines searched ie:
data1
data2
data3
info required
info required
info required
data44
data45
etc
data3 and data44 will always be constant so using awk I can:
awk '/^data3/,/^data44/ {print $0}' file
data3
info required
info required
info required
data44
how can I ommit data3 and data44?
Thanks
Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2009 06:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2009 06:50 AM
тАО07-21-2009 06:50 AM
Re: Search between two lines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2009 06:59 AM
тАО07-21-2009 06:59 AM
Re: Search between two lines
Similar to Laurent's:
# perl -ne '$x++,next if /data3/;$x-- if /data44/;print if $x' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2009 07:03 AM
тАО07-21-2009 07:03 AM
Re: Search between two lines
awk 'BEGIN {s=0}/^data3/{s=1; continue}/^data44/ {s=2; break} (s==1){print $0}' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2009 07:14 AM
тАО07-21-2009 07:14 AM
Re: Search between two lines
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2009 12:27 AM
тАО07-22-2009 12:27 AM
Re: Search between two lines
I would have never thought to use continue/break since these are only used in C to break/continue out of loops or case. Not separate patterns. I don't think your break really does anything.
Instead I would use next and exit:
awk '
BEGIN {s=0}
/^data3/ {s=1; next}
/^data44/ {exit}
s {print $0}'
Of course your solution will find multiple ranges of data3/data44 pairs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2009 02:33 AM
тАО07-22-2009 02:33 AM
Re: Search between two lines
continue/break just does the same
as a next in that context.
I made that error for years, thanks.