- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: parse a file and merge another file (before a ...
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
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
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
11-14-2012 09:26 AM
11-14-2012 09:26 AM
hello ,
i have a new issue due this thread
parse a file and merge another file
i want to insert another file before a fix defined mark and keep the mark.
in the other solution the marks will be replace with the variable insert file
START_TOKEN="TEST_MARK" ./filter.pl variable1 template
#!/usr/bin/perl -i use strict; use warnings; my $start = $ENV{START_TOKEN} || die "no START token defined\n"; my $varfile = shift or die "Usage $0: varfile infile\n"; open( my $fh, "<", $varfile ) or die "can't open '$varfile': $!\n"; my @contents = <$fh>; close $fh; while (<>) { if ( /^$start/ ) { /$start/ and print @contents; printf "\n$start\n"; next; } print; } 1;
are the changes in regulatory ? a little wish will be , when a blank line before the "mark" exists , can this blank file maybe removed ?
regards
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2012 06:58 PM
11-16-2012 06:58 PM
Solution>are the changes in regulatory?
Do you mean are they correct? You could just try it.
>when a blank line before the "mark" exists, can this blank line be removed?
Something like this:
my $was_blank = 0;
while (<>) {
if ( /^\s$/ ) { # found blank line
if ($was_blank) {
printf "\n"; # multiple blank lines, print all but last
}
$was_blank = 1;
next; # suppress
}
if ( /^$start/ ) {
/$start/ and print @contents; printf "\n$start\n";
next;
}
if ($was_blank) {
printf "\n"; # print previous blank line
$was_blank = 0;
}
print;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2012 02:36 AM
12-03-2012 02:36 AM
Re: parse a file and merge another file (before a mark)
hello,
i tested your version and in same cases i have to insert a blank line. so i extended with my moderate skills your version :
START_TOKEN="TEST_MARK" ./filter.pl Y variable1 template # Y ... YES and insert a blank line
START_TOKEN="TEST_MARK" ./filter.pl N variable1 template
use strict; use warnings; my $was_blank = 0; my $start = $ENV{START_TOKEN} || die "no START token defined\n"; my $insert_blank_line = shift or die "Usage $0: blank_line([Y|N]) varfile infile [n-infile]\n"; my $varfile = shift or die "Usage $0: blank_line([Y|N]) varfile infile [n-infile]\n"; my $chr_line = ($insert_blank_line eq 'Y' ? "\n" : ""); open( my $fh, "<", $varfile ) or die "can't open '$varfile': $!\n"; my @contents = <$fh>; close $fh; while (<>) { if ( /^\s$/ ) { # found blank line if ($was_blank) { printf "\n"; # multiple blank lines, print all but last } $was_blank = 1; next; # suppress } if ( /^$start/ ) { /$start/ and printf "$chr_line"; print @contents; printf "\n$start"; next; } if ($was_blank) { printf "\n"; # print previous blank line $was_blank = 0; } print; } 1;
regards