<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>梁剑的Blog &#187; awk</title>
	<atom:link href="http://icomes.net/tag/awk/feed/" rel="self" type="application/rss+xml" />
	<link>http://icomes.net</link>
	<description>做有趣的事，做有用的人</description>
	<lastBuildDate>Sat, 05 Nov 2011 18:23:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>删除多余换行的awk命令</title>
		<link>http://icomes.net/2009/02/03/%e5%88%a0%e9%99%a4%e5%a4%9a%e4%bd%99%e6%8d%a2%e8%a1%8c%e7%9a%84awk%e5%91%bd%e4%bb%a4/</link>
		<comments>http://icomes.net/2009/02/03/%e5%88%a0%e9%99%a4%e5%a4%9a%e4%bd%99%e6%8d%a2%e8%a1%8c%e7%9a%84awk%e5%91%bd%e4%bb%a4/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 14:56:23 +0000</pubDate>
		<dc:creator>梁剑</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技术笔记]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[电子书]]></category>

		<guid isPermaLink="false">http://icomes.net/?p=303</guid>
		<description><![CDATA[找到了txt版本的天龙八部，准备放到手机上，但发现这个版本略有瑕疵。 可能是为了在固定宽度的显示器上显示的缘故，往往到了一定字数，文章就会折行。 萧峰道：“不行！”突然拍出一掌，击向木几，只听得劈拍一声响，木几碎成 数块，匕首随而跌落，凛然说道：“杀母大仇，岂可当作买卖交易？此仇能报便报， 如不能报，则我父子毕命于此便了。这等肮脏之事，岂是我萧氏父子所屑为？” 慕容博仰天大笑，朗声说道：“我素闻萧峰萧大侠才略盖世，识见非凡，殊不 知今日一见，竟虽个不明大义、徒逞意气的一勇之夫。嘿嘿，可笑啊可笑！” 萧峰知他是以言语相激，冷冷的道：“萧峰是英雄豪杰也罢，是凡夫俗子也罢， 总不能中你圈套，成为手中的杀人之刀。” 慕容博道：“食君之禄，忠君之事。你是大辽国这臣，欲只记得父母私仇，不 思尽忠报国，如何对得起大辽？” 萧峰蹭上一步，昂然说到：“你可曾见过边关之上、宋辽相互仇杀的惨状？可 曾见过宋人辽人妻离子散、家破人亡的情景？宋辽之间好容易罢兵数十年，倘若刀 兵再起，契丹铁骑侵入南朝，你可知将有多少宋人惨遭横死？多少辽人死于非命？” 他说到这里，想起当日雁门关外宋兵和辽兵相互打草谷的残酷情状，越说越响，又 道：“兵凶战危，世间岂有必胜之事？大宋兵多财足，只须有一二名将，率兵奋战， 大辽、吐蕃联手，未必便能取胜。咱们打一个血流成河，尸骨如山，欲让你慕容氏 来乘机兴复燕国，我对大辽尽忠报国，是在保土安民，而不是为了一己的荣华富贵， 因而杀人取地、建功立业。” 忽听得长窗外一个苍老的声音说道：“善哉，善哉！萧居士宅心仁厚，如此以 天下苍生为念，当真是菩萨心肠。” 这样的格式在640*480的屏幕上可能很好，但是在iPhone上看殊为不爽。 解决方法： awk 'BEGIN{ while(getline){ if( $0 !~ /^$/ ) printf $0; else printf &#34;\n&#34; } } END{printf &#34;\n&#34;}' filename 找解决方法的过程中，发现了两个附加产品： 下载txt电子书的网站（不是论坛，无需注册，虽然广告很多） GNU的awk手册（比种种学习笔记要好得多） 曾尝试用sed，不果。 Update: 20090206 针对中文书，优化了一下 for f in *; do awk 'BEGIN{ [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Windows的休眠命令" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2007%2F09%2F16%2Fwindows%25E7%259A%2584%25E4%25BC%2591%25E7%259C%25A0%25E5%2591%25BD%25E4%25BB%25A4%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F02%2F03%2F%25E5%2588%25A0%25E9%2599%25A4%25E5%25A4%259A%25E4%25BD%2599%25E6%258D%25A2%25E8%25A1%258C%25E7%259A%2584awk%25E5%2591%25BD%25E4%25BB%25A4%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows的休眠命令</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Ubuntu 8.04 Server在VMWare中无法启动的解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2008%2F06%2F29%2Fubuntu-804-server%25E5%259C%25A8vmware%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E5%2590%25AF%25E5%258A%25A8%25E7%259A%2584%25E8%25A7%25A3%25E5%2586%25B3%25E5%258A%259E%25E6%25B3%2595%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F02%2F03%2F%25E5%2588%25A0%25E9%2599%25A4%25E5%25A4%259A%25E4%25BD%2599%25E6%258D%25A2%25E8%25A1%258C%25E7%259A%2584awk%25E5%2591%25BD%25E4%25BB%25A4%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15017346.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Ubuntu 8.04 Server在VMWare中无法启动的解决办法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Second Screenshot" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2009%2F09%2F03%2Fsecond-screensho%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F02%2F03%2F%25E5%2588%25A0%25E9%2599%25A4%25E5%25A4%259A%25E4%25BD%2599%25E6%258D%25A2%25E8%25A1%258C%25E7%259A%2584awk%25E5%2591%25BD%25E4%25BB%25A4%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15015227.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Second Screenshot</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="浏览器战争" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2009%2F01%2F13%2F%25E6%25B5%258F%25E8%25A7%2588%25E5%2599%25A8%25E6%2588%2598%25E4%25BA%2589%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F02%2F03%2F%25E5%2588%25A0%25E9%2599%25A4%25E5%25A4%259A%25E4%25BD%2599%25E6%258D%25A2%25E8%25A1%258C%25E7%259A%2584awk%25E5%2591%25BD%25E4%25BB%25A4%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15015466.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">浏览器战争</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>找到了txt版本的天龙八部，准备放到手机上，但发现这个版本略有瑕疵。<br />
可能是为了在固定宽度的显示器上显示的缘故，往往到了一定字数，文章就会折行。</p>
<blockquote><p>萧峰道：“不行！”突然拍出一掌，击向木几，只听得劈拍一声响，木几碎成<br />
数块，匕首随而跌落，凛然说道：“杀母大仇，岂可当作买卖交易？此仇能报便报，<br />
如不能报，则我父子毕命于此便了。这等肮脏之事，岂是我萧氏父子所屑为？”</p>
<p>慕容博仰天大笑，朗声说道：“我素闻萧峰萧大侠才略盖世，识见非凡，殊不<br />
知今日一见，竟虽个不明大义、徒逞意气的一勇之夫。嘿嘿，可笑啊可笑！”</p>
<p>萧峰知他是以言语相激，冷冷的道：“萧峰是英雄豪杰也罢，是凡夫俗子也罢，<br />
总不能中你圈套，成为手中的杀人之刀。”</p>
<p>慕容博道：“食君之禄，忠君之事。你是大辽国这臣，欲只记得父母私仇，不<br />
思尽忠报国，如何对得起大辽？”</p>
<p>萧峰蹭上一步，昂然说到：“你可曾见过边关之上、宋辽相互仇杀的惨状？可<br />
曾见过宋人辽人妻离子散、家破人亡的情景？宋辽之间好容易罢兵数十年，倘若刀<br />
兵再起，契丹铁骑侵入南朝，你可知将有多少宋人惨遭横死？多少辽人死于非命？”<br />
他说到这里，想起当日雁门关外宋兵和辽兵相互打草谷的残酷情状，越说越响，又<br />
道：“兵凶战危，世间岂有必胜之事？大宋兵多财足，只须有一二名将，率兵奋战，<br />
大辽、吐蕃联手，未必便能取胜。咱们打一个血流成河，尸骨如山，欲让你慕容氏<br />
来乘机兴复燕国，我对大辽尽忠报国，是在保土安民，而不是为了一己的荣华富贵，<br />
因而杀人取地、建功立业。”</p>
<p>忽听得长窗外一个苍老的声音说道：“善哉，善哉！萧居士宅心仁厚，如此以<br />
天下苍生为念，当真是菩萨心肠。”</p></blockquote>
<p>这样的格式在640*480的屏幕上可能很好，但是在iPhone上看殊为不爽。<br />
解决方法：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'BEGIN{ while(getline){ if( $0 !~ /^$/ ) printf $0; else printf &quot;\n&quot; } }  END{printf &quot;\n&quot;}'</span>  filename</pre></div></div>

<p>找解决方法的过程中，发现了两个附加产品：</p>
<ol>
<li><a href="http://www.bookdown.com.cn/" target="_blank">下载txt电子书的网站</a>（不是论坛，无需注册，虽然广告很多）</li>
<li><a href="http://www.gnu.org/manual/gawk/html_node/index.html" target="_blank">GNU的awk手册</a>（比种种学习笔记要好得多）</li>
</ol>
<p>曾尝试用sed，不果。</p>
<p>Update: 20090206<br />
针对中文书，优化了一下</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'BEGIN{ while(getline){ if( $0 !~ /^[ \t\xa1]+/ ) printf $0; else printf &quot;\r\n%s&quot;, $0 } }  END{printf &quot;\n&quot;}'</span>  <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$f</span>.new; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>xA1A1是全角的\t</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Windows的休眠命令" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2007%2F09%2F16%2Fwindows%25E7%259A%2584%25E4%25BC%2591%25E7%259C%25A0%25E5%2591%25BD%25E4%25BB%25A4%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F02%2F03%2F%25E5%2588%25A0%25E9%2599%25A4%25E5%25A4%259A%25E4%25BD%2599%25E6%258D%25A2%25E8%25A1%258C%25E7%259A%2584awk%25E5%2591%25BD%25E4%25BB%25A4%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows的休眠命令</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Ubuntu 8.04 Server在VMWare中无法启动的解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2008%2F06%2F29%2Fubuntu-804-server%25E5%259C%25A8vmware%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E5%2590%25AF%25E5%258A%25A8%25E7%259A%2584%25E8%25A7%25A3%25E5%2586%25B3%25E5%258A%259E%25E6%25B3%2595%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F02%2F03%2F%25E5%2588%25A0%25E9%2599%25A4%25E5%25A4%259A%25E4%25BD%2599%25E6%258D%25A2%25E8%25A1%258C%25E7%259A%2584awk%25E5%2591%25BD%25E4%25BB%25A4%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15017346.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Ubuntu 8.04 Server在VMWare中无法启动的解决办法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="The Last Lecture" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2011%2F10%2F15%2Fthe-last-lecture%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F02%2F03%2F%25E5%2588%25A0%25E9%2599%25A4%25E5%25A4%259A%25E4%25BD%2599%25E6%258D%25A2%25E8%25A1%258C%25E7%259A%2584awk%25E5%2591%25BD%25E4%25BB%25A4%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/10/15/9228539.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">The Last Lecture</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="阅读空间的GM脚本" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2009%2F01%2F17%2F%25E9%2598%2585%25E8%25AF%25BB%25E7%25A9%25BA%25E9%2597%25B4%25E7%259A%2584gs%25E8%2584%259A%25E6%259C%25AC%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F02%2F03%2F%25E5%2588%25A0%25E9%2599%25A4%25E5%25A4%259A%25E4%25BD%2599%25E6%258D%25A2%25E8%25A1%258C%25E7%259A%2584awk%25E5%2591%25BD%25E4%25BB%25A4%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15015260.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">阅读空间的GM脚本</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://icomes.net/2009/02/03/%e5%88%a0%e9%99%a4%e5%a4%9a%e4%bd%99%e6%8d%a2%e8%a1%8c%e7%9a%84awk%e5%91%bd%e4%bb%a4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

