{"id":219,"date":"2004-07-30T23:32:16","date_gmt":"2004-07-31T04:32:16","guid":{"rendered":"http:\/\/ywwg.com\/wordpress\/?p=219"},"modified":"2004-07-30T23:32:16","modified_gmt":"2004-07-31T04:32:16","slug":"unwordwrap-a-file","status":"publish","type":"post","link":"https:\/\/ywwg.com\/wordpress\/archives\/219","title":{"rendered":"unwordwrap a file"},"content":{"rendered":"<p>I hate when I get a text file that I want to load onto my Palm device, and I find it&#8217;s already full of newlines.  When I use <a href=\"http:\/\/homepage.mac.com\/pauljlucas\/software\/txt2pdbdoc\/\">txt2pdbdoc<\/a> the pre-wrapped lines end up making the display of the file a headache to use.  It&#8217;s like old emails you used to receive:<\/p>\n<p>Hi, my name is Owen<br \/>\nWilliams<br \/>\nand for some reason<br \/>\nmy<br \/>\nsoftware is a little narrower<br \/>\nthan<br \/>\nyours so everything<br \/>\nlooks<br \/>\nlike crap.<\/p>\n<p>Well here&#8217;s a python script that will remove newlines from any text file.  It&#8217;s really quick and stupid. (See extended entry)<br \/>\n<!--more--><br \/>\n&#8212;&#8212;&#8212;&#8212;unwordwrap.py&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<blockquote><p>#!\/usr\/bin\/python<br \/>\nimport sys<br \/>\nif len(sys.argv)<2:\n&nbsp;&nbsp;&nbsp;print \"Need a file to unwrap\"\n&nbsp;&nbsp;&nbsp;sys.exit()\n\t\nf=open(sys.argv[1], 'r')\nwhile 1==1:\n&nbsp;&nbsp;&nbsp;try:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line=f.readline()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if line==\"\\n\":\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print \"\\n\"\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print line[0:len(line)-1],\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if len(line)==0:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break\n&nbsp;&nbsp;&nbsp;except ValueError:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break<\/p><\/blockquote>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;EOF&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I hate when I get a text file that I want to load onto my Palm device, and I find it&#8217;s already full of newlines. When I use txt2pdbdoc the pre-wrapped lines end up making the display of the file a headache to use. It&#8217;s like old emails you used to receive: Hi, my name &hellip; <a href=\"https:\/\/ywwg.com\/wordpress\/archives\/219\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;unwordwrap a file&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/posts\/219"}],"collection":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":0,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"wp:attachment":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}