<?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>夜行人 &#187; shell</title>
	<atom:link href="http://www.187299.com/archives/tag/shell/feed" rel="self" type="application/rss+xml" />
	<link>http://www.187299.com</link>
	<description>寻觅生命中的那一片浅草......</description>
	<lastBuildDate>Wed, 16 Nov 2011 11:25:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A rsync script with openvpn</title>
		<link>http://www.187299.com/archives/1561</link>
		<comments>http://www.187299.com/archives/1561#comments</comments>
		<pubDate>Mon, 26 Apr 2010 07:58:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1561</guid>
		<description><![CDATA[#mkdir /data/conf/openvpn up is a file containing vpn username/password on 2 lines #vi /data/conf/openvpn/up username password #vi /data/sh/rsync_my_files.sh #!/bin/bash #start openvpn in background cd /data/conf/openvpn /usr/sbin/openvpn --config openvp... ]]></description>
			<content:encoded><![CDATA[<p>#mkdir /data/conf/openvpn</p>
<p>up is a file containing vpn username/password on 2 lines</p>
<p>#vi /data/conf/openvpn/up<br />
username<br />
password</p>
<p>#vi /data/sh/rsync_my_files.sh<br />
#!/bin/bash</p>
<p>#start openvpn in background<br />
cd /data/conf/openvpn<br />
/usr/sbin/openvpn --config openvpn.ovpn --auth-user-pass up --daemon</p>
<p>/usr/bin/rsync -vazu --password-file=/data/conf/rsync.pass rsy_user@192.168.1.100::db_file /data/backup/db_file</p>
<p>#disconnect from vpn server after synchronization<br />
pkill openvpn</p>
<p>make rsync_my_files.sh executable</p>
<p>#chmod 700 /data/sh/rsync_my_files.sh</p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1561/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>统计几个目录大小的sh</title>
		<link>http://www.187299.com/archives/1519</link>
		<comments>http://www.187299.com/archives/1519#comments</comments>
		<pubDate>Tue, 23 Mar 2010 06:56:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1519</guid>
		<description><![CDATA[#!/bin/bash #目录名类似于20100315,20100315long,20100316,20100316zhong,20100317等 #用法 sh count_dir_size.sh 日期最小数，日期最大数 #如果是2010-03-15到2010-03-17，则sh count_dir_size.sh 2010-03-15 2010-03-17 #Author johncan，201... ]]></description>
			<content:encoded><![CDATA[<p>#!/bin/bash<br />
#目录名类似于20100315,20100315long,20100316,20100316zhong,20100317等<br />
#用法 sh count_dir_size.sh 日期最小数，日期最大数<br />
#如果是2010-03-15到2010-03-17，则sh count_dir_size.sh 2010-03-15 2010-03-17<br />
#Author johncan，2010-03-22<br />
#COUNT_DATE=`date "+%Y%m%d" |cut -c1-5`<br />
if [ -z "$1" ]<br />
then<br />
echo "please use $0 start_day end_day"<br />
exit 1<br />
fi</p>
<p>#将开始时间转换成时间戳<br />
STA_TIME=`date -d "$1" +%s`<br />
#将结束时间转换成时间戳<br />
END_TIME=`date -d "$2" +%s`</p>
<p>cd /dir_which_files_are_stored</p>
<p>DR_TIME=${STA_TIME}<br />
while [ "${DR_TIME}" -le "${END_TIME}" ]<br />
do<br />
#将时间戳转换为目录名的格式<br />
STAND_DR_TIME=`date -d "1970-01-01 UTC ${DR_TIME} seconds" +%Y%m%d`<br />
for DR in ${STAND_DR_TIME}*<br />
do<br />
#统计目录大小<br />
DR_SIZE=`du -s ${DR} | awk '{print $1}'`<br />
let "COUNT_DR_SIZE=${COUNT_DR_SIZE}+${DR_SIZE}"<br />
done<br />
let "DR_TIME=${DR_TIME}+86400"<br />
done<br />
echo ${COUNT_DR_SIZE}KB</p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1519/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>awk打印单引号</title>
		<link>http://www.187299.com/archives/1465</link>
		<comments>http://www.187299.com/archives/1465#comments</comments>
		<pubDate>Wed, 03 Feb 2010 23:35:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1465</guid>
		<description><![CDATA[awk 'BEGIN{print "'\''"}' awk '{print " '\'' "}' 其中： '\'' 这三个' 都是单引号 转载自：http://bbs.chinaunix.net/viewthread.php?tid=15773&#38;extra=&#38;page=... ]]></description>
			<content:encoded><![CDATA[<p>awk 'BEGIN{print "'\''"}'</p>
<p>awk '{print " '\'' "}'<br />
其中： '\''  这三个' 都是单引号</p>
<p>转载自：http://bbs.chinaunix.net/viewthread.php?tid=15773&amp;extra=&amp;page=2</p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1465/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sed删除某关键字的下一行到最后一行</title>
		<link>http://www.187299.com/archives/1459</link>
		<comments>http://www.187299.com/archives/1459#comments</comments>
		<pubDate>Fri, 29 Jan 2010 08:15:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1459</guid>
		<description><![CDATA[[root@test200 ~]# cat test a b c d e f [root@test200 ~]# sed '/c/{p;:a;N;$!ba;d}' test a b c 定义一个标签a，匹配c，然后N把下一行加到模式空间里，匹配最后一行时，才退出标签循环，然后命令d，把这个模式空间... ]]></description>
			<content:encoded><![CDATA[<p>[root@test200 ~]# cat test<br />
a<br />
b<br />
c<br />
d<br />
e<br />
f<br />
[root@test200 ~]# sed '/c/{p;:a;N;$!ba;d}' test<br />
a<br />
b<br />
c</p>
<p>定义一个标签a，匹配c，然后N把下一行加到模式空间里，匹配最后一行时，才退出标签循环，然后命令d，把这个模式空间里的内容全部清除。</p>
<p>if 匹配"c"<br />
:a<br />
追加下一行<br />
if 不匹配"$"<br />
goto a<br />
最后退出循环，d命令删除。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1459/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>当while遇到重定向----sh的陷阱</title>
		<link>http://www.187299.com/archives/1456</link>
		<comments>http://www.187299.com/archives/1456#comments</comments>
		<pubDate>Mon, 25 Jan 2010 02:58:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1456</guid>
		<description><![CDATA[以下是我在编程时的亲身体会： 先看如下的程序： #!/bin/sh count=0 while read LINE do count=`expr $count + 1` done &#60; file echo $count 问题是这个程序能得到什么样的结果?仿佛很明显，能够统计文件file的行... ]]></description>
			<content:encoded><![CDATA[<p>以下是我在编程时的亲身体会：<br />
先看如下的程序：<br />
#!/bin/sh</p>
<p>count=0<br />
while read LINE<br />
do<br />
count=`expr $count + 1`<br />
done &lt; file<br />
echo $count<br />
问题是这个程序能得到什么样的结果?仿佛很明显，能够统计文件file的行数，然而你若执行一下便知，无论file的行数是多少，该程序的输出始终是0！为什么？<br />
原来如果使用for,while,until,if,case这些命令时用到了重定向，那么sh会产生一个子shell来运行它们。可以想象count在循环体中能够正确的计数，一旦while执行完毕，子shell完成，其内部的变量count就消失了。因而得到的结果是循环体外开始赋的值0！<br />
可以避免吗？试试这样：<br />
cat file|while read LINE<br />
do<br />
count=`expr $count + 1`<br />
done<br />
echo $count<br />
依然如此！怎么办？可以先关闭标准输入，然后以你要读取得文件重新打开它，这样就不需要对while命令的输入进行改向，也就不会用子shell的方式来运行它了。如下：<br />
exec&lt;file<br />
count=0<br />
while read LINE<br />
do<br />
count=`expr $count + 1`<br />
done<br />
exec &lt; /dev/tty<br />
echo $count<br />
也可以<br />
exec 4&lt;&amp;amp;0 0&lt; file<br />
count=0<br />
while read LINE<br />
do<br />
count=`expr $count + 1`<br />
done<br />
exec 0&lt;&amp;amp;4<br />
echo $count<br />
如果还有怀疑的话可以试一下if：<br />
#!/bin/sh</p>
<p>echo &amp;quot;abcd&amp;quot;|if [ &amp;quot;abcd&amp;quot; = &amp;quot;abcd&amp;quot; ]; then<br />
var=7<br />
fi<br />
echo $var<br />
输出当然是空。去掉echo &amp;quot;abcd&amp;quot;|就好了。<br />
所以不了解这一点在编程时就会非常危险，试想while,for,case,if,until是多么的常用，与管道或重定向连着用也是很常见的，可是一旦在其内部使用了什么变量，就是有进无出，有去无回了。<br />
以上的说法仅限于sh编程，对于ksh,bash，据我所知都不会有这个问题，它们处理的时候不会当作子shell来做。其它种类的shell可以自己试一试。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1456/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>当while read 遇上ssh</title>
		<link>http://www.187299.com/archives/1453</link>
		<comments>http://www.187299.com/archives/1453#comments</comments>
		<pubDate>Mon, 25 Jan 2010 02:54:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1453</guid>
		<description><![CDATA[http://hi.baidu.com/test/blog/item/16ecf01f6f46e4f7e0fe0b10.html 当while read 遇上ssh 2007-08-15 21:13先看一段简化过的BASH SHELL代码 TODAY=`date +%Y%m%d` SUFFIX="tar" CONF=the_config_file i=0 while read HOST SRCPATH DSTPATH do (( i++ )) if [... ]]></description>
			<content:encoded><![CDATA[<p>http://hi.baidu.com/test/blog/item/16ecf01f6f46e4f7e0fe0b10.html</p>
<p>当while read 遇上ssh<br />
2007-08-15 21:13先看一段简化过的BASH SHELL代码</p>
<p>TODAY=`date +%Y%m%d`<br />
SUFFIX="tar"<br />
CONF=the_config_file<br />
i=0</p>
<p>while read HOST SRCPATH DSTPATH<br />
do<br />
(( i++ ))<br />
if [ "X${HOST:0:1}" = "X#" -o ${#DSTPATH} -eq 0 ]<br />
then<br />
#忽略注释行及少于3个项的记录<br />
else<br />
ssh ${HOST} "tar c ${SRCPATH}" &gt;${DSTPATH}.${TODAY}.${SUFFIX} 2&gt;/dev/null<br />
fi<br />
done &lt; $CONF</p>
<p>作者的本意是通过脚本读取配置文件$CONF，然后打包备份$CONF中指定的文件，但执行后发现程序在成功备份$CONF中指定的第一个文件后即退出……</p>
<p>跟踪后发现read在备份完第一个文件后就再读不到任何数据，所以while循环结束－－也就是说，<br />
通过重定向$CONF文件传给标准输入的数据被</p>
<p>ssh ${HOST} "tar c ${SRCPATH}" &gt;${DSTPATH}.${TODAY}.${SUFFIX} 2&gt;/dev/null</p>
<p>这个命令提前吃掉了。</p>
<p>将其改为<br />
ssh ${HOST} "tar c ${SRCPATH}" &gt;${DSTPATH}.${TODAY}.${SUFFIX} 2&gt;/dev/null &lt;/dev/null</p>
<p>将ssh的标准输入重定向到/dev/null，程序正常备份所有$CONF中指定的文件。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1453/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>while read line的一些问题</title>
		<link>http://www.187299.com/archives/1451</link>
		<comments>http://www.187299.com/archives/1451#comments</comments>
		<pubDate>Mon, 25 Jan 2010 02:53:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1451</guid>
		<description><![CDATA[while read line的一些问题 Q1. 曾经面试的时候被问到一个问题， 说 while read line ; do echo $line ; done &#60; ./a.txt 失败， 会是什么原因， 当时觉得不太可能， 就回答了“我用的时候没有碰到过这种情... ]]></description>
			<content:encoded><![CDATA[<p>while read line的一些问题</p>
<p>Q1. 曾经面试的时候被问到一个问题， 说<br />
while read line ; do<br />
echo $line ;<br />
done &lt; ./a.txt<br />
失败， 会是什么原因， 当时觉得不太可能， 就回答了“我用的时候没有碰到过这种情况”。 前段在写一个脚本的时候， 确实遇到了所谓的while read 失败， 原因是我读入的文件是在win下用dos格式保存的文本， 所以每行结束都带有一个\r字符， 这个字符在linux/unix环境下的作用是“回到一行的开始”， 如果再对$line做相关的字符串操作的话（比如字符串连接）， 得到的结果可能会让人迷惑... 所以当把win下编译的文本用在linux/unix环境时， 最好做一下格式转换</p>
<p>Q2.  2009-08-01更新：<br />
# cat ur_file<br />
1234 abcd<br />
5678 efgh</p>
<p># vi t3.sh<br />
#!/bin/bash</p>
<p>while read t1 t2 ; do<br />
echo $t1 $t2 ; awk '{ print $0 }'<br />
done &lt; ./ur_file</p>
<p>#./t3.sh<br />
1234 abcd<br />
5678 efgh</p>
<p># sh -x ./t3.sh 发现只read 了一次</p>
<p>Q3.</p>
<p># seq 10 &gt; file<br />
# while read line ; do<br />
&gt; echo $line<br />
&gt; dd &amp;&gt;/dev/null<br />
&gt; done &lt; ./file<br />
1</p>
<p>为什么这里只打印第一行呢？<br />
问题的关键在于：<br />
read从输入读取了一行内容后，<br />
其它的程序(比如 rsh或sed)从同样的地方把其它的输入读走了，<br />
read当然读不到其它内容了，<br />
while也就结束了</p>
<p>摘自：http://bbs.chinaunix.net/viewthread.php?tid=769040&amp;extra=&amp;page=2</p>
<p>可以打开set -x， 看看， 确实只read了两次， 第一次read出第一行， 第二次read不到就退出while循环<br />
read 和 dd都从文件描述符3中读取数据</p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1451/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell里非交互式修改用户密码</title>
		<link>http://www.187299.com/archives/1439</link>
		<comments>http://www.187299.com/archives/1439#comments</comments>
		<pubDate>Fri, 08 Jan 2010 14:21:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1439</guid>
		<description><![CDATA[echo "newpasswd" &#124; passwd user --stdi... ]]></description>
			<content:encoded><![CDATA[<p>echo "newpasswd" | passwd user --stdin</p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1439/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>comp.unix.shell FAQ 阅读笔记</title>
		<link>http://www.187299.com/archives/1413</link>
		<comments>http://www.187299.com/archives/1413#comments</comments>
		<pubDate>Tue, 15 Dec 2009 01:57:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1413</guid>
		<description><![CDATA[最近在阅读一个比较经典的关于shell的faq，全文链接在这里http://home.comcast.net/~j.p.h/ 作者将comp.unix.shell新闻组上的常见问题总结了一下，做成faq的形式，对学习很有帮助。 不打算全文翻译了，仅... ]]></description>
			<content:encoded><![CDATA[<p>最近在阅读一个比较经典的关于shell的faq，全文链接在这里http://home.comcast.net/~j.p.h/</p>
<p>作者将comp.unix.shell新闻组上的常见问题总结了一下，做成faq的形式，对学习很有帮助。</p>
<p>不打算全文翻译了，仅把认为比较重要的部分总结一下，做个备案吧</p>
<p>1.UUOC(useless use of cat)</p>
<p>避免 cat file | tr -d ‘xyz’ ，因为这样实际上跑了两个进程cat 和 tr</p>
<p>应该采用输入重定向 tr -d ‘xyz’ &lt;file</p>
<p>2.shebang</p>
<p>脚本第一行是告诉操作系统解释器路径的，如果用解释器显式调用脚本文件,</p>
<p>那么第一行只是注释而已，可有可无。</p>
<p>3.echo 在不同的shell里的解释方式可能不同，要熟悉你的shell是如何做的。</p>
<p>优先采用cat输出变量</p>
<p>cat&lt;&lt;EOF</p>
<p>$a</p>
<p>EOF</p>
<p>4.随机数生成方法</p>
<p>最portable的方法是利用awk内置的srand和rand函数</p>
<p>awk ‘BEGIN {srand();print rand()}’</p>
<p>5.dos和unix文本文件之间转换</p>
<p>dos格式的文本文件，行末尾是<br />
(CR LF)</p>
<p>unix格式的文本文件，行末尾是</p>
<p>所以dos格式文本在unix下显式的时候，尾部会多一个^M</p>
<p>二者转换方式是</p>
<p>dos—unix  : sed ’s/^M$//’ dos.txt &gt; unix.txt或者tr -d ‘<br />
‘ &lt;dosfile &gt;unixfile</p>
<p>unix—dos: sed ’s/$/^M/’ unix.txt &gt;dos.txt</p>
<p>另外，也可以用dos2unix unix2dos等现成工具</p>
<p>6.改变term窗口的标题</p>
<p>两种方法</p>
<p>$ echo -en “33]2;XXX07″</p>
<p>$ printf ‘%b’ ‘e]2;XXXa’</p>
<p>7.如何设定用户输入超时</p>
<p>bash里面可以用read的参数-t 设置超时</p>
<p>也可以利用终端属性完成</p>
<p>{</p>
<p>s=$(stty -g)</p>
<p>stty -icanon min 0 time 100</p>
<p>var=$(head -n 1)</p>
<p>stty “$s”</p>
<p>}</p>
<p>8. bash脚本一定要注意空格的使用</p>
<p>$ [ -f xxx ] isn’t the same as</p>
<p>$ [-f xxx ]</p>
<p>9.如何从路径中分离目录和文件</p>
<p>pathname=’/path/to/some/file’</p>
<p>dir=`dirname “$pathname”`</p>
<p>file=`basename “$pathname”`</p>
<p>缺点是，fork出了新进程</p>
<p>可以使用shell内置的字符串处理机制</p>
<p>pathname=/path/to/some/file</p>
<p>file=${pathname##*/}</p>
<p>case $pathname in</p>
<p>*/*) dir=${pathname%/*};;</p>
<p>*) dir=”</p>
<p>esac</p>
<p>10.如何删除特殊字符开头的文件</p>
<p>例如删除 -foo，有三种方法</p>
<p>rm -foo</p>
<p>rm — -foo</p>
<p>rm -i — * （进入交互模式，提示动作）</p>
<p>转载自：<a href="http://www.oolec.com/compunixshell-faq-study-note/ " target="_blank">http://www.oolec.com/compunixshell-faq-study-note/ </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1413/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>删除文本中的重复行(sort+uniq/awk/sed)</title>
		<link>http://www.187299.com/archives/1393</link>
		<comments>http://www.187299.com/archives/1393#comments</comments>
		<pubDate>Fri, 11 Dec 2009 03:13:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.187299.com/?p=1393</guid>
		<description><![CDATA[在进行文本处理的时候，我们经常遇到要删除重复行的情况。那怎么解决呢？ 下面就是三种常见方法？ 第一，用sort+uniq，注意，单纯uniq是不行的。 shell&#62; sort file &#124; uniq 这里我做了个简单... ]]></description>
			<content:encoded><![CDATA[<p>在进行文本处理的时候，我们经常遇到要删除重复行的情况。那怎么解决呢？<br />
下面就是三种常见方法？<br />
第一，用sort+uniq，注意，单纯uniq是不行的。<br />
shell&gt; sort file | uniq</p>
<p>这里我做了个简单的测试，当file中的重复行不再一起的时候，uniq将服务删除所有的重复行。经过排序后，所有相同的行都在相邻，因此unqi可以正常删除重复行。</p>
<p>第二，用sort+awk命令，注意，单纯awk同样不行，原因同上。<br />
shell&gt; sort file | awk '{if ($0!=line) print;line=$0}'</p>
<p>当然，自己把管道后面的代码重新设计一下，可能不需要sort命令先排序拉。</p>
<p>第三，用sort+sed命令，同样需要sort命令先排序。<br />
shell&gt; sort file | sed '$!N; /^\(.*\)\n\1$/!P; D'</p>
<p>最后附一个必须先用sort排序的文本的例子，当然，这个需要用sort排序的原因是很简单，就是后面算法设计的时候的“局部性”，相同的行可能分散出现在不同的区域，一旦有新的相同行出现，那么前面的已经出现的记录就被覆盖了，看了这个例子就好理解拉。<br />
ffffffffffffffffff<br />
ffffffffffffffffff<br />
eeeeeeeeeeeeeeeeeeee<br />
fffffffffffffffffff<br />
eeeeeeeeeeeeeeeeeeee<br />
eeeeeeeeeeeeeeeeeeee<br />
gggggggggggggggggggg</p>
<p>其实，这是我随便打进去的几行字，没想到就是必须用sort的很好例子，大家可以自己试试看。</p>
<p>参考资料：</p>
<p>[1] SED单行脚本快速参考</p>
<p>http://linux.chinaitlab.com/administer/381792.html</p>
<p>[2] 如何删除重复的行（sed或awk）</p>
<p>http://www.linuxsir.org/bbs/showthread.php?t=132848</p>
<p>转载自：http://www.91linux.com/html/article/shell/20090205/15636.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.187299.com/archives/1393/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

