<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>hnw</author_name>
  <author_url>https://blog.hatena.ne.jp/hnw/</author_url>
  <blog_title>hnwの日記</blog_title>
  <blog_url>https://hnw.hatenablog.com/</blog_url>
  <categories>
  </categories>
  <description>テキストファイルの末尾に改行がたくさんついてたり、逆に1個もついていなかったりすることってありますよね。たくさんあるファイルについて、末尾改行1個だけの形に統一したいなー、と思ったら意外と苦労したので紹介します。 本当はもっとシンプルに書けそうな気もするんですが…。 perl -i.bak -pe 'BEGIN{undef $/}s/([^\n])\n*$/$1\n/;' hoge.txt ポイントは「undef $/」です。$/は入力の区切り文字を意味し、デフォルトでは改行文字となっています。これを未定義値にすると、1行を取得しようとしてファイル全体を取得するので、改行を跨いだ置換が可能にな…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fhnw.hatenablog.com%2Fentry%2F20091226&quot; title=&quot;ファイル末尾の連続する改行を取り除く - hnwの日記&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2009-12-26 00:00:00</published>
  <title>ファイル末尾の連続する改行を取り除く</title>
  <type>rich</type>
  <url>https://hnw.hatenablog.com/entry/20091226</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
