<?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://cocobear.info/blog/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://cocobear.info/blog</link>
	<description>K.I.S.S</description>
	<lastBuildDate>Sat, 10 Dec 2011 16:11:01 +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>shell脚本解题6</title>
		<link>http://cocobear.info/blog/2008/08/19/07-issues-shell/</link>
		<comments>http://cocobear.info/blog/2008/08/19/07-issues-shell/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 07:42:19 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[编程相关]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=297</guid>
		<description><![CDATA[问题： 执行命令前暂时回home目录，执行后跳回来 解法： 1. (cd ~; ls; ) 使用子shell的方式去执行命令； 把这行 gs.AddMany( [b_cls,b_bck,t_blank,b_close,b_7,b_8,b_9,b_div,b_4,b_5,b_6,b_mul,b_1,b_2,b_3,b_minus,b_0,b_dot,b_equal,b_plus, ]) 进行替换，每一个元素替换为类似(b_cls,0,EXPAND)这样 解法1. sed 's/[b&#124;t]_[^,]*,/(&#38;0,EXPAND)/g' 如果使用 's/[b&#124;t]_.*?,/(&#38;0,EXPAND)/g' 则不能得出正确的结果，因为sed不支持.*?这样的非贪婪匹配；解法中使用[^,]避免了贪婪匹配。 有如下内容,想要获取 8B E5 55 这些内容： [cocobear@cocobear ~]$ cat file.txt 00401038 8B E5 mov esp,ebp 0040103A 55 push ebp 0040103B 8B EC mov ebp,esp 0040103D 33 FF xor edi,edi 0040103F 57 push edi 004010A9 FF D0 [...]]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2008/08/19/07-issues-shell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>处理了下网站</title>
		<link>http://cocobear.info/blog/2008/08/15/deal-with-wes/</link>
		<comments>http://cocobear.info/blog/2008/08/15/deal-with-wes/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 09:57:53 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=305</guid>
		<description><![CDATA[改了info域名后网站以前里很多页面里有cocobear.cn，连一些图片也显示不出来，今天就处理了一下： 把网站里一些文件做替换，先备份一下： grep cocobear.cn ./cocobear.info/ -R -l &#8211;binary-files=without-match&#124;xargs -i cp &#8211;parents {} bk/ 然后全部替换： grep cocobear.cn ./cocobear.info/ -R -l &#8211;binary-files=without-match &#124; xargs sed -i &#8216;s/cocobear\.cn[^@]/cocobear\.info/g&#8217; 剩下就是数据库里的内容了，主要是wp_posts表中的post_content字段，还有guid字段，还有wp_comments中的comment_author_url，wp_postmeta中的meta_value; 操作的命令是： mysql> update wp_posts set post_content=replace(post_content,&#8221;http://www.cocobear.cn&#8221;,&#8221;http://cocobear.info&#8221;); 当然在进行数据库操作时一定要记得先备份一下： mysqldump -h mysql.1g50.cn -u cocobear -p cocobear > 0808151.sql 使用 mysqldump -h mysql.1g50.cn -u cocobear -p cocobear < 0808151.sql恢复似乎不太好，还是进mysql里使用source ~/0808151.sql进行恢复。]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2008/08/15/deal-with-wes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>shell脚本解题5</title>
		<link>http://cocobear.info/blog/2008/07/24/06-issues-shell/</link>
		<comments>http://cocobear.info/blog/2008/07/24/06-issues-shell/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 09:37:36 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[编程相关]]></category>
		<category><![CDATA[awk]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=295</guid>
		<description><![CDATA[问题： 随机输出目录下5个文件： 解法： 1. #! /bin/bash arr=($(ls *.sql.gz)) len=$((${#arr[@]}+1)) for((i=1;i&#38;lt;6;i++)) do RANDOM=$(($$+i)) echo ${arr[$((RANDOM%len))]} done 这种方法有可能会产生重复的文件。 2. ls * 'BEGIN {srand()} {A[NR]=$0;} END {for(i=0;i&#38;lt;5;++i) { n=int(rand()*FNR)+1; print A[n]} }' 同样这个也有可能重复。 3. ls *sql.gz &#124; awk 'BEGIN{srand()}{a[rand()&#34; &#34;NR]=$0}END{for(i in a) {print a[i];if(++j==5) break}}' 将600个同一目录下的文件随机分成3份，每份200个： 解法： 1. ls &#124; awk 'BEGIN{srand();b[1]=&#34;path1&#34;;b[2]=&#34;path2&#34;;b[3]=&#34;path3&#34;}{a[rand()&#34; &#34;NR]=$0}END{for(i in a){if(k++%200==0) j++;print &#34;mv &#34;a[i]&#34; [...]]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2008/07/24/06-issues-shell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell脚本解题4</title>
		<link>http://cocobear.info/blog/2008/07/18/05-issues-shell/</link>
		<comments>http://cocobear.info/blog/2008/07/18/05-issues-shell/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 08:24:32 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[编程相关]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=294</guid>
		<description><![CDATA[问题： 用sed把每行的第二个字符到第六个字符替换成星号 原文 123456 1234567 12345 要求结果 1***** 1*****7 1**** 解法： 1. sed '/^../{h;s/^.\(.\{1,5\}\).*/\1/;s/./*/g;G;s/\(.*\)\n\(.\).\{1,5\}\(.*\)/\2\1\3/}' 2. sed -r '/.{6}/bb :a s/(.\**)[^*]/\1\*/ ta b :b /^.\*{5}/! { s/(.\**)[^*]/\1\*/ tb }' 3. awk '{a=(substr($0,2,5));gsub(/./,&#34;*&#34;,a);print substr($0,1,1)a&#34;&#34;substr($0,7,length($0))}' 4. sed 's/^\(.\)\(.\{1,5\}\)\(.*\)/\1\n\2\n\3/' file &#124; sed '{n; s/./*/g;n}' &#124; sed '{N; N; s/\n//g}' 5. sed ':a;/^.[*]\{5\}/!{s/\(.[*]*\)./\1*/;/*$/!ta}' 问题： 比较2008-01-29和2008-02-1之间相差月份 解法： 1. echo &#34;$date1-$date2&#34; &#124; [...]]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2008/07/18/05-issues-shell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>shell脚本解题3</title>
		<link>http://cocobear.info/blog/2008/07/16/04-issues-shell/</link>
		<comments>http://cocobear.info/blog/2008/07/16/04-issues-shell/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 05:15:42 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[编程相关]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=291</guid>
		<description><![CDATA[问题： 如何将命令的输出信息按行放入到数组里面? 解法： 1. n=0 while read line;do array[$n]=&#34;$line&#34; ((n++)) done &#60; &#60;(traceroute 192.168.1.1 -n) echo ${array[0]} 问题： sed 可以同时匹配多个条件？ 比如 file: AAA BBB CCC DDD AAA BBB DDD CCC DDD sed能实现，同时匹配AAA和CCC就打印,在一条命令中 解法： 1. sed -n '/AAA/{/CCC/p}' 同时匹配kobe和james: sed -n &#8216;/kobe/{/james/p}&#8217; awk &#8216;/kobe/&#038;&#038;/james/{ print $0 }&#8217; 匹配kobe或james: sed -n &#8216;/\(kobe\&#124;james\)/p&#8217; awk &#8216;/kobe/&#124;&#124;/james/{ print $0 }&#8217; [...]]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2008/07/16/04-issues-shell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>shell脚本解题2</title>
		<link>http://cocobear.info/blog/2008/07/15/03-issues-shell/</link>
		<comments>http://cocobear.info/blog/2008/07/15/03-issues-shell/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 09:12:33 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[编程相关]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=292</guid>
		<description><![CDATA[问题： 如下文本 60.208.0.224 60.208.103.192 131.9.124.72 60.208.20.119 60.208.20.9 2.110.213.40 8.56.32.24 60.53.37.128 60.3.98.1 怎么先按ip的第一位sort，然后按第二位sort，然后按第三，第四 结果是这样 2.110.213.40 8.56.32.24 60.3.98.1 60.53.37.128 60.208.0.224 60.208.20.9 60.208.20.119 60.208.103.192 131.9.124.72 解法： 1. sort -t. -k1,1n -k2,2n -k3,3n -k4,4n 2. sed 's/\./ /g' urfile&#124;sort -nt ' ' -k1 -k2 -k3 -k4&#124;sed 's/ /./g' 问题： httpd.conf文件中含有以下内容，要把Directory块中含有/usr/local/apache/cgi-bin这一块注释掉： Options Indexes MultiViews FollowSymLinks AllowOverride None Order allow,deny Allow [...]]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2008/07/15/03-issues-shell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>shell脚本解题1</title>
		<link>http://cocobear.info/blog/2008/07/10/02-issues-shell/</link>
		<comments>http://cocobear.info/blog/2008/07/10/02-issues-shell/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 05:28:24 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[编程相关]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=289</guid>
		<description><![CDATA[问题：请教如何得到一个目录树的最深目录路径？ 解法： 1. find -type d &#124; awk '{if( max &#60; gsub(/\//,&#34;/&#34;)) {max= gsub(/\//,&#34;/&#34;);maxp=$0&#34;/&#34;} else if (max == gsub(/\//,&#34;/&#34;)) maxp=maxp&#34;\n&#34;$0&#34;/&#34;} END{print maxp}' 2. find -type d -printf &#34;%d %p\n&#34; &#124; sort -nrk1 &#124; awk 'NR==1{a=$1}a==$1{print $2}' 问题：我想将包含read的行放在echo单词的后面 解法： sed '/read/{h;d};/echo/{G;s/\(.*echo\)\(.*\)\n\(.*\)/\1\3\2/}' urfile 问题：怎么copy一个目录中的某些文件，但保持目录结构？ 比如说，我想copy sourcedir\a\b\c.java sourcedir\a\b\c.cs sourcedir\a\b\d.java sourcedir\a\b\d.cs 到 destdir\a\b\c.java destdir\a\b\d.java 解法: 1. rsync -av --include='*.java' [...]]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2008/07/10/02-issues-shell/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>shell脚本解题</title>
		<link>http://cocobear.info/blog/2008/07/07/01-issue-shell/</link>
		<comments>http://cocobear.info/blog/2008/07/07/01-issue-shell/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 02:27:55 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[编程相关]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=287</guid>
		<description><![CDATA[以下内容来自http://bbs.chinaunix.net/thread-1189933-1-1.html 现有数据，每一行中各个段间的分隔为多个空格，如下 　　AAB BB CCC A2B CB ABC 如何实现，转换成下面的格式 AAB&#124;BB&#124;CCC&#124; A2B&#124;CB&#124;ABC&#124; awk解法： 1. [cocobear@cocobear ~]$ awk &#8216;BEGIN{OFS=&#8221;&#124;&#8221;} {$1=$1;print}&#8217; test.txt AAB&#124;BB&#124;CCC A2B&#124;CB&#124;ABC 结果最后少一个&#8221;&#124;&#8221; 2. [cocobear@cocobear ~]$ awk &#8216;{print $1&#8243;&#124;&#8221;$2&#8243;&#124;&#8221;$3&#8243;&#124;&#8221;}&#8217; test.txt AAB&#124;BB&#124;CCC&#124; A2B&#124;CB&#124;ABC&#124; 3. [cocobear@cocobear ~]$ awk -v OFS=&#8217;&#124;&#8217; &#8216;NF++&#8217; test.txt AAB&#124;BB&#124;CCC&#124; A2B&#124;CB&#124;ABC&#124; sed解法： 1. [cocobear@cocobear ~]$ sed &#8216;s/^ \+//;s/ \+/&#124;/g;s/ *$/&#124;/;&#8217; test.txt AAB&#124;BB&#124;CCC&#124; A2B&#124;CB&#124;ABC&#124; 2. [cocobear@cocobear [...]]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2008/07/07/01-issue-shell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>诡异的shell脚本错误</title>
		<link>http://cocobear.info/blog/2007/12/21/erorr-of-shell-script/</link>
		<comments>http://cocobear.info/blog/2007/12/21/erorr-of-shell-script/#comments</comments>
		<pubDate>Fri, 21 Dec 2007 14:32:37 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[编程相关]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/2007/12/21/%e8%af%a1%e5%bc%82%e7%9a%84shell%e8%84%9a%e6%9c%ac%e9%94%99%e8%af%af/</guid>
		<description><![CDATA[今天为了方便拨号，改了改以前写的拨号脚本，没想到遇到了一个问题：使用awk分析一个文本文件时总会在我截取的第二个字段后多加一个^M（也就是r）。很自然的想到vim打开这个文本文件确认这个文件原本是否有没有“^M”,很奇怪vim里面这个文件行末没有这个东西。又和王聪在一起研究了半天我写的这个awk脚本，还试着用head+tail+cut把脚本重写了一遍，结果问题仍然存在。这时我不得不怀疑这个文本文件是不是有问题，不放心刚才看过一遍，又打开看了一次，仍然没有发现任何异常，在我们束手无策的时候突然注意到了在打开这个文本文件时vim左下脚闪了一下&#8221;dos&#8221;这几个字符，这时我们才恍然大悟，原来是眼睛欺骗了我们，vim把这个文本文件按照dos(windows)下文本进行了显示，所以^M是合法的换行，没有被显示出来。 眼睛看到的东西未必是可信的！]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2007/12/21/erorr-of-shell-script/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>关于.bashrc[管理主机时遇到的问题]</title>
		<link>http://cocobear.info/blog/2007/04/11/%e5%85%b3%e4%ba%8ebashrc/</link>
		<comments>http://cocobear.info/blog/2007/04/11/%e5%85%b3%e4%ba%8ebashrc/#comments</comments>
		<pubDate>Wed, 11 Apr 2007 06:05:28 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://cocobear.info/wordpress/?p=61</guid>
		<description><![CDATA[习惯了Fedora core 下在.bashrc这个文件中设置一些常用的环境变量，以及alias，这几天在服务器上边通过修改.bashrc文件在里面加入一些alias，但是每次登录进来并不能生效，必须使用source命令才行，给提供商发一份邮件，没想到没分钟就收到了，这会儿也不知道是美国时间的什么时候，真是感叹他们的办事效率，原来是和bash_profile这个文件有关的，其实从shell登录以后最开始是寻找/etc/profile，然后搜索~/.bash_profile, ~/.bash_login, 和 ~/.profile，而Fedora core 中的.basr_profile文件里面是： # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH unset USERNAME 这样就清楚了，.bashrc文件是通过.bash_profile来生效的，好了，在服务器上把这段代码加入，以后登录服务器就可以使用自己shell下常用的一些设置了，方便的很，呵呵。 因为服务器上没有lftp，觉得下东西的时候不太方便，试了一下可不可以自己装一下，于是在自己的目录下创建opt目录，编译安装lftp的时候使用选项： &#8211;prefix=/home/cocobear/opt/lftp 这样，就可以在服务器上使用好用的lftp了，呵呵，Linux主机太强大了！！]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2007/04/11/%e5%85%b3%e4%ba%8ebashrc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

