- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl help
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
08-21-2006 11:12 PM
08-21-2006 11:12 PM
I want to parse a file with perl.
a
b
c
d
e
Is the file and i want to have contents "b" to "d"
sed -n '/b/,/d/p' file.txt
does it.
How can it be done via perl.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2006 11:20 PM
08-21-2006 11:20 PM
Re: Perl help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2006 11:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2006 11:37 PM
08-21-2006 11:37 PM
Re: Perl help
Just in case you were wondering about awk:
# awk '/b/,/d/' file.txt
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2006 12:10 AM
08-22-2006 12:10 AM
Re: Perl help
Peter, i think your command only works if the line starts with that. I had some words in mid-way.
James: Bingo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2006 12:16 AM
08-22-2006 12:16 AM
Re: Perl help
my mis-understanding of the input file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2006 12:19 AM
08-22-2006 12:19 AM
Re: Perl help
This is my first twist with perl.
One more hint needed.
How do i put it in perl script:
I was writing something like:
print "if '/\*\*\* BOM report/../----- BUILD/'" /usr/local/path/a.txt
Got error
Illegal division by zero.
What am i doing wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2006 12:28 AM
08-22-2006 12:28 AM
Re: Perl help
# echo "\*\*\* BOM report" > myfile
# echo "da da da" >> myfile
# echo "---- BUILD/" >> myfile
# perl -nle 'print if /\\*\\*\\* BOM report/../----- BUILD/' myfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2006 12:34 AM
08-22-2006 12:34 AM
Re: Perl help
I have a huge file, midway it contains text like
blah
blah
*** BOM report
blah
---- BUILD
blah
This is what i am parsing.
I want to run that file from inside a perl script, as the file is getting generated from within the script itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2006 01:00 AM
08-22-2006 01:00 AM
Re: Perl help
You say that the file that you want to parse is "...generated within the script itself".
Is the script in question a Perl script or a shell script?
If it's a Perl script then close the file; reopen it; and parse it; something like this, perhaps:
...
open(F, "<", "/tmp/build") or die "Cannot open: $!\n";
while (
$ok=1 if /BOM/;
print if $ok;
last if /BUILD/;
}
...
...If the script is a shell script, you can simply embed the perl snippet I offered within the shell script just like you would spawn an 'awk' or 'sed' snippet.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2006 01:02 AM
08-22-2006 01:02 AM
Re: Perl help
Okay, i will try the Open-Close thingy and let you know.
Thanks