- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: perl hack: commenting lines between two marker...
Operating System - HP-UX
1755703
Members
5073
Online
108837
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО03-10-2010 06:30 AM
тАО03-10-2010 06:30 AM
Hey;
I'm having a hard time wrapping my mind around this one this morning; maybe under-caffeinated..
I have a text file with two markers between which I want to be able to comment (or uncomment) lines.
I've got a beginning:
#!/usr/bin/perl
use strict;
my @lines = <>; my $lines = join*('',@lines);
my ($chunk) = $lines =~ m{^# mcsg_begins\n(.*?)#mcsg_ends}mgs;
$chunk =~ s/^/# /mg;
print $chunk;
That comments out the lines between the markers but only in the variable $chunk; I can't, for instance, print out $lines and have the stanza commented.
Anyone have a slick way of doing this? Extra helping of eternal gratitude if there's a way to do it with a perl one-liner...
Thanks for any hints/tips/suggestions.
Doug O'Leary
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
I'm having a hard time wrapping my mind around this one this morning; maybe under-caffeinated..
I have a text file with two markers between which I want to be able to comment (or uncomment) lines.
I've got a beginning:
#!/usr/bin/perl
use strict;
my @lines = <>; my $lines = join*('',@lines);
my ($chunk) = $lines =~ m{^# mcsg_begins\n(.*?)#mcsg_ends}mgs;
$chunk =~ s/^/# /mg;
print $chunk;
That comments out the lines between the markers but only in the variable $chunk; I can't, for instance, print out $lines and have the stanza commented.
Anyone have a slick way of doing this? Extra helping of eternal gratitude if there's a way to do it with a perl one-liner...
Thanks for any hints/tips/suggestions.
Doug O'Leary
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Solved! Go to Solution.
- Tags:
- Perl
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2010 06:40 AM
тАО03-10-2010 06:40 AM
Re: perl hack: commenting lines between two markers?
Hi Doug:
# perl -pe 's/^(.)/#$1/ if (/mcsg_begins/../mcsg_ends/)' myfile
...where:
# cat myfile
line-1
line-2
line-3
mcsg_begins
line-1.1
line-2.1
line-3.1
mcsg_ends
line-4
line-5
line-6
...yielding:
line-1
line-2
line-3
#mcsg_begins
#line-1.1
#line-2.1
#line-3.1
#mcsg_ends
line-4
line-5
line-6
Regards!
...JRF...
# perl -pe 's/^(.)/#$1/ if (/mcsg_begins/../mcsg_ends/)' myfile
...where:
# cat myfile
line-1
line-2
line-3
mcsg_begins
line-1.1
line-2.1
line-3.1
mcsg_ends
line-4
line-5
line-6
...yielding:
line-1
line-2
line-3
#mcsg_begins
#line-1.1
#line-2.1
#line-3.1
#mcsg_ends
line-4
line-5
line-6
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2010 06:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2010 06:57 AM
тАО03-10-2010 06:57 AM
Re: perl hack: commenting lines between two markers?
Outstanding! I knew there was a better way to do that than what I was coming up with!
Thanks alot!
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Thanks alot!
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP