Remove linebreak at specific position in textfile

Posted by williamx on Stack Overflow See other posts from Stack Overflow or by williamx
Published on 2010-03-18T08:54:47Z Indexed on 2010/03/18 9:21 UTC
Read the original article Hit count: 475

Filed under:
|
|

I have a large textfile, which has linebreaks at column 80 due to console width. Many of the lines in the textfile are not 80 characters long, and are not affected by the linebreak. In pseudocode, this is what I want:

  • Iterate through lines in file
  • If line matches this regex pattern: ^(.{80})\n(.+)
    • Replace this line with a new string consisting of match.group(1) and match.group(2). Just remove the linebreak from this line.
  • If line doesn't match the regex, skip!

Maybe I don't need regex to do this?

© Stack Overflow or respective owner

Related posts about python

Related posts about regex