www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > Perl

    Perl Discussion and technical support for using and deploying Perl.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-06-2009, 04:29 PM
    edatz edatz is offline
    Registered User
     
    Join Date: Jun 2008
    Posts: 74
    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.
    Reply With Quote
      #2  
    Old 11-07-2009, 12:16 PM
    Sixtease's Avatar
    Sixtease Sixtease is offline
    Registered User
     
    Join Date: Oct 2007
    Location: Prague, Czech Republic
    Posts: 237
    untested:
    Code:
    perl -pe 'print "\n" if not $. % 20' < input_file > output_file
    Reply With Quote
      #3  
    Old 11-11-2009, 03:37 AM
    edatz edatz is offline
    Registered User
     
    Join Date: Jun 2008
    Posts: 74
    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.
    Reply With Quote
      #4  
    Old 11-11-2009, 03:47 AM
    Sixtease's Avatar
    Sixtease Sixtease is offline
    Registered User
     
    Join Date: Oct 2007
    Location: Prague, Czech Republic
    Posts: 237
    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++; }
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 09:15 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.