寻觅生命中的那一片浅草......

如何查找: 连续的多行内容

例如,我有一个文件包含这样的内容,我需要查找给变量abc和k连续赋值得语句(连续两句)

…..
abc=13               这里是符合条件的地方
k=12
…..

abc=5                 单独给abc赋值,不符合条件

…..
…..
abc=14               这个也是符合条件的地方
k=5
……

也就是说,如果我单独用两个grep来查找的话,肯定会得到很多不符合条件的结果。
如何才能达到前面我描述的需求呢? 也就是说,我希望的过滤结果像下面这样:
abc=13
k=12
abc=14
k=5
解答:

awk ‘/abc=/{s=$0;getline;if (/k=/) print s”\n”$0}’ file

sed -n ‘/abc=/{N;/k=/p}’ file

while read line
do
echo $line | grep -q k= && echo $pre | grep -q abc= && echo $pre && echo $line
pre=$line
done<file

来自:http://bbs3.chinaunix.net/viewthread.php?tid=1604893

设置XenServer中的Linux vm从光驱启动

xenserver中的windows vm安装后可以通过xencenter设置从光驱启动,而linux vm则没有这样的选项,可以通过以下命令行解决:
xe vm-param-set uuid=546f896a-ebe6-8071-2c31-b9214dc1d1b5 HVM-boot-policy=BIOS\ order
xe vm-param-set uuid=546f896a-ebe6-8071-2c31-b9214dc1d1b5 HVM-boot-params:order=”dc”
uuid为vm的uuid,order中的d表明光驱,c表明启动硬盘。这样设置完后通过xencenter中的虚机属性也可以设置启动顺序了。

http://home.vmsky.com/space-32409-do-blog-id-3408.html

secureCRT断开服务器连接

解决的方法:

在session options->Terminal->Anti-idle->send protocol NO-OP every?seconds.

关闭360 V6.0的守护进程

如果你确定一定要禁止该服务,请打开安全卫士--实时保护--高级设置--保护360安全卫士--关闭自我保护后,还有核心保护也要关闭,然后进入进程服务管理(随便你怎么进!)禁止启用即可。

我觉得要是你真不喜欢多的这些进程,你最起码也要在控制面板里把该进程设置为手动,因为这几个进程真的很重要!

来自:霏凡论坛

“不许联想”mp3player.xml处理

<?xml version=”1.0″ encoding=”UTF-8″?>
<player showDisplay=”yes” showPlaylist=”yes” autoStart=”no”> <song path=”http://music.u148.net/Kris_Kristofferson-holy_woman.mp3″ title=”Kris_Kristofferson-holy_woman” /> <song path=”http://music.u148.net/public_image_ltd-disappointed.mp3″ title=”public_image_ltd-disappointed” /> <song path=”http://music.u148.net/Muse-Uprising.mp3″ title=”Muse-Uprising” /> <song path=”http://music.u148.net/Orla_Fallon-She_Moved_Thro_the_Fair.mp3″ title=”Orla_Fallon-She_Moved_Thro_the_Fair” /> <song path=”http://music.u148.net/damon_and_naomi-E.T.A.mp3″ title=”damon_and_naomi-E.T.A.” /> <song path=”http://music.u148.net/England_Dan_And_John_Ford_Coley-Who_s_Lonely_Now.mp3″ title=”England_Dan_And_John_Ford_Coley-Who_s_Lonely_Now” /> <song path=”http://music.u148.net/the_avett_brothers-will_you_return.mp3″ title=”the_avett_brothers-will_you_return” /> <song path=”http://music.u148.net/richard_hawley-ashes_on_the_fire.mp3″ title=”richard_hawley-ashes_on_the_fire” /> <song path=”http://music.u148.net/avion_travel-abbassando.mp3″ title=”avion_travel-abbassando” /> <song path=”http://music.u148.net/Elisabeth_Kontomanou-I_gotta_right_to_sing_the_blues.mp3″ title=”Elisabeth_Kontomanou-I_gotta_right_to_sing_the_blues” /> <song path=”http://music.u148.net/Matthew_Barber-Easily_bruised.mp3″ title=”Matthew_Barber-Easily_bruised” /> <song path=”http://music.u148.net/Pearl_Jam-Just_Breathe.mp3″ title=”Pearl_Jam-Just_Breathe” /> <song path=”http://music.u148.net/Hope_Sandoval_&_The_Warm_Inventions-Wild_Roses.mp3″ title=”Hope_Sandoval_&_The_Warm_Inventions-Wild_Roses” /> <song path=”http://music.u148.net/u2-ill_go_crazy_if_i_dont_go_crazy_tonight.mp3″ title=”u2-ill_go_crazy_if_i_dont_go_crazy_tonight” /> <song path=”http://music.u148.net/Monsters_Of_Folk-Say_Please.mp3″ title=”Monsters_Of_Folk-Say_Please” /> <song path=”http://music.u148.net/Andres_Cepeda-Faltarán.mp3″ title=”Andres_Cepeda-Faltarán” /> <song path=”http://music.u148.net/Mark_Mulcahy-Be_Sure.mp3″ title=”Mark_Mulcahy-Be_Sure” /> <song path=”http://music.u148.net/Brett_Dennen-San Francisco.mp3″ title=”Brett_Dennen-San Francisco” /> <song path=”http://music.u148.net/Hnir_Pan-Piyka.mp3″ title=”Hnir_Pan-Piyka” /> <song path=”http://music.u148.net/KAYAH-EMBARCACAO.mp3″ title=”KAYAH-EMBARCACAO” /> <song path=”http://music.u148.net/Mosh_Ben_Ari-Bein_hazlilim.mp3″ title=”Mosh_Ben_Ari-Bein_hazlilim” /> <song path=”http://music.u148.net/the_black_crowes-appaloosa.mp3″ title=”the_black_crowes-appaloosa” /></player>

今天想去下载王小峰博客上的音乐,像往常一样,把http://www.wangxiaofeng.net/mp3player.xml拉回来,发现格式都乱了,像以上,只有2行(<player ×××>到</player>为一行)。
想过将http与mp3之间的内容提取出来,但不知道如何入手,最后想出先将它分行,再提出mp3地址

sed “s/<song/\n\r<song/g” mp3player.xml |cut -d\” -f2

输出,有首歌的歌名不是英文,乱码了,Mark_Mulcahy-Be_Sure.mp3

















http://music.u148.net/Brett_Dennen-San Francisco.mp3


注意,如果是vi mp3player.xml,替换时,换行符则只有\r,而用sed时则是\n\r
:s/<song/\r<song/g

Windows下用Notepad++打开正则表达式进行替换,换行符是\n

单命令用

grep -oP ‘(?<=song path=”)[^”]*(?=” title=)’ mp3player.xml

更简单的

grep -o ‘http[^”]*\.mp3’ mp3player.xml

2025年七月
« 5月    
 123456
78910111213
14151617181920
21222324252627
28293031