in reply to Break continuous lines of a text file based on character lengths

here's an untested one-liner. Give it a try on a non-critical 'filename.txt' and see if that's what you're after.

perl -pi.bak -e 'BEGIN{$/=\104;}$_ .= qq/\n/;' filename.txt

HTH


Dave

  • Comment on Re: Break continuous lines of a text file based on character lengths
  • Download Code

Replies are listed 'Best First'.
Re(2): Break continuous lines of a text file based on character lengths
by bart (Canon) on Apr 20, 2004 at 15:36 UTC
    If you set $\ to "\n", you don't even need the second statement — at least, not for every loop. Using the -l command line switch, you don't even need any code.
    perl -pi.bak -e 'BEGIN{$/=\104;$\=qq/\n/}' filename.txt
    or
    perl -lpi.bak -e 'BEGIN{$/=\104}' filename.txt
    For Windows, you'll have to adapt the quote characters around the code.
      I wouldn't have immediately guessed that the -l switch would work because the POD for perlrun states that if a value is omitted from the -l switch, it sets $\ equal to $/. Since we're changing the value of $/ in the BEGIN{} block, and since the BEGIN{} block executes at least before the -p switch, I figured that using -l would set $\ to \104. Obviously that's not the case and I was just overthinking it.

      Good call bart. Great one-liner!


      Dave

      Thanks Bart! The one liner did work marvel for me.