- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl - read between lines in 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
05-17-2004 07:05 AM
05-17-2004 07:05 AM
I was wondering if anyone had a better way to read between lines in a file. I can do it with a few loops, but it is messy and time consuming. I'd like a better way.
The file would be:
A
bunch of lines
B
bunch of lines
C
bunch of lines
D
and I want the "bunch of lines" between line B and line C. I will know what line B and line C are, but nothing else in the file.
Anybody know a really clean way to do this in Perl?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2004 07:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2004 07:13 AM
05-17-2004 07:13 AM
Re: Perl - read between lines in a file
#!/usr/bin/sh
FLAG=N
LINE1="Text of line you want to start printing from"
LINE2="Text of line you want to stop printing"
while read LINE
do
if [ "${LINE}" = "${LINE2}" ] ; then
FLAG=N
fi
if [ "${FLAG}" = "Y" ] ; then
echo ${LINE}
fi
if [ "${LINE}" = "${LINE1}" ] ; then
FLAG=Y
fi
done < inputfile
I think something like that should work. If that doesn't work it should be pretty close.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2004 07:17 AM
05-17-2004 07:17 AM
Re: Perl - read between lines in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2004 07:33 AM
05-17-2004 07:33 AM
Re: Perl - read between lines in a file
perl -ne '$seq=/^B/../^C/; print if ($seq > 1 and substr($seq,-2) ne "E0")' inputfile
This will exclude the "B" and "C" lines
HTH
-- Rod Hills