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

文章带标签 Linux

“不许联想”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

vi快捷键

h 左
j 下
k 上
l 右
w 词首
e 词末
$ 行末
^ 行首
) 将光标移到下一句句首
( 将光标移到上一句句首
} 将光标移到下一段开始处
{ 将光标移到下一段开始处
M 光标移至屏幕中间行
z. 将光标所在行移至屏幕中部
[[ 条到文件头(gg)
]] 跳到文件尾(G)
:n 跳到第n行(nG)
ctrl+g 显示光标所在信息
Ctrl+u 向上滚动半屏
Ctrl+d 向下滚动半屏
Ctrl+f 向前翻一页
Ctrl+b 向后翻一页

x 删除字符
i 光标前插入
a 光标后插入
A 行末插入
R 替换内容
r 替换所选字符
d 删除
c 修改
dd 删除整行
2dd 删除2整行
u 撤消
U 撤消整行
ctrl+r 重做
p 粘贴最后删除的内容
yw 把光标所在单词移到缓冲区
yy 把当前行整行移到缓冲区
~ 改变光标所在字符大小写
. 重复上一个操作
<< 把当前行左移
>> 把当前行右移
:x 保存退出
:q 退出
:q! 不保存退出

/ 查找内容
? 向上查找内容
n 下一匹配
N 上一匹配
% 匹配下一半“大中小”括号
:%s/a/b/g 替换文件中a为b
:! 执行外部命令,回车返回

:set ic 忽略大小写
:set hls 匹配高亮
:set is 即时匹配输入
:set nu 显示行号
:x 加密文件
:ab c d 以d替代c

shell快捷键

bash
ctrl – a 光标移到行首
ctrl – e 光标移到行尾
ctrl – l  刷新屏幕
ctrl – u 从光标处删除到行首
ctrl – k 从光标处删除到行尾
ctrl – b 光标往后移动一个字符
ctrl – f  光标往前移动一个字符
ctrl – y 恢复被删除的收入
ctrl – p 显示之前执行的命令
ctrl – n 显示之后执行的命令
ctrl – j  执行输入的命令
ctrl – x 光标移动到行首或行尾
ctrl – c 中断程序执行
ctrl – h 删除前一个字符
ctrl – d 删除后一个字符  — 当光标处无输入时,  退出shell
ctrl – s 关闭ssh流缓冲区
ctrl – q 重启ssh流缓冲区
ctrl – r  搜索之前输入过的命令
ctrl – z 是进程暂停

转载自:http://blog.csdn.net/gggxin/archive/2009/07/27/4383481.aspx

Bash shell becomes inactive on Ctrl+S

The Ctrl+S shortcut key sequence activates XOFF which is used to pause the sending of data etc (read more here at Wikipedia about software flow control). In the Bash shell this buffers all your commands and won’t run them until you send XON which is done with Ctrl+Q.

I only learnt about this a few days ago when I accidentally pressed Ctrl+S while doing something on one of my webservers – I was meaning to press Ctrl+D to logout which is the only reason I knew which keystroke I had hit instead. It had baffled me years ago why my Bash shell suddenly became unresponsive when I’d hit what appeared to be some random keystroke combination. When it happened to me a few days ago I decided to work out why it does this and what the solution is. I remember in the past having to kill my CLI session because I didn’t know what else to do.

So in summary, it’s Ctrl+S which suspends the output and you need to hit Ctrl+Q to resume output again

Linux在shell中为用户添加计划任务crontab

比较简单,这样就可以了

cat > /var/spool/cron/root <<EOF
* * * * * /usr/sbin/ntpdate cn.pool.ntp.org >> /var/log/ntpdate.log
EOF

额外的资料
1.copy or backup
#crontab -l > /tmp/root.crontab
2.edit
edit root.crontab by vi,emacs, ed ,etc etc .
3.activate
#crontab /tmp/root.crontab

2025年六月
« 5月    
 1
2345678
9101112131415
16171819202122
23242526272829
30