|
|||||||
| Perl Discussion and technical support for using and deploying Perl. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Inserting blank lines
Is there a way to insert a blank line into a text file, say every 20 or 30 lines?
I have a largish text file that needs to have the blank lines so stuff can be copied and pasted easily. Trouble is there over 1000 lines (I don't know how to do command line blackbox stuff). Any help appreciated. |
|
#2
|
||||
|
||||
|
untested:
Code:
perl -pe 'print "\n" if not $. % 20' < input_file > output_file |
|
#3
|
|||
|
|||
|
Thanks, I'm up to my eyeballs in a client project at the moment and will try to do something with this later on.
I think it's command line, so not sure what to do, but will see if I can figure out how to convert it to script. |
|
#4
|
||||
|
||||
|
in a stand-alone script:
Code:
#!/usr/bin/env perl
use strict;
open my $in, '<', "/path/to/input/file.txt" or die "Couldn't open input file";
open my $out, '>', "/path/to/output/file.txt" or die "Couldn't open output file";
my $i = 1;
while (<$in>) {
print {$out} $_;
print {$out} "\n" if $i % 20 == 0;
} continue { $i++; }
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|