首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

一个shell的小疑惑,该怎么处理

2012-03-04 
一个shell的小疑惑find somedir -type l -print0|xargs -r0 file|grep broken symbolic|sed -e s/^\|

一个shell的小疑惑
find "somedir" -type l -print0|xargs -r0 file|grep "broken symbolic"|sed -e 's/^\|: *broken symbolic.*$/"/g'

在此处 ”xargs -r0 file“ 做何解释?
“'s/^\|: *broken symbolic.*$/" ”----如何理解??

[解决办法]

xargs 参数-0 说明传入字符串以null字符结尾, 空格, 引号 反斜扛不做特殊处理. 并传给file命令

后面那个sed是替换

[解决办法]
sed -e 's/^|: *broken symbolic.*$/"/g' 
^从记录开头匹配 字符|: ( *)空格 *标识0个或者多个 字符broken symbolic
.*:.标识1个字符 .*标识所有字符 $记录尾 .*$标识匹配到记录尾所有字符 替换成"

这条应该不行吧,^标识从字符串开头匹配,而你现在这句要替换的并不在开头

#cat csdn_test
/usr/share/omf/gnome-bluetooth/gnome-bluetooth-ru.omf:broken symbolic link to `/usr/share/omf-langpack/gnome-bluetooth/gnome-bluetooth-ru.omf'
/usr/share/omf/gnome-bluetooth/gnome-bluetooth-ru.omf: broken symbolic link to `/usr/share/omf-langpack/gnome-bluetooth/gnome-bluetooth-ru.omf'
/usr/share/omf/gnome-bluetooth/gnome-bluetooth-ru.omf: broken symbolic link to `/usr/share/omf-langpack/gnome-bluetooth/gnome-bluetooth-ru.omf'
:broken symbolic link to `/usr/share/omf-langpack/gnome-bluetooth/gnome-bluetooth-ru.omf'
: broken symbolic link to `/usr/share/omf-langpack/gnome-bluetooth/gnome-bluetooth-ru.omf'

执行:
开头匹配,只替换后面的两条记录
#sed -e 's/^: *broken symbolic.*$/"/g' csdn_test
/usr/share/omf/gnome-bluetooth/gnome-bluetooth-ru.omf:broken symbolic link to `/usr/share/omf-langpack/gnome-bluetooth/gnome-bluetooth-ru.omf'
/usr/share/omf/gnome-bluetooth/gnome-bluetooth-ru.omf: broken symbolic link to `/usr/share/omf-langpack/gnome-bluetooth/gnome-bluetooth-ru.omf'
/usr/share/omf/gnome-bluetooth/gnome-bluetooth-ru.omf: broken symbolic link to `/usr/share/omf-langpack/gnome-bluetooth/gnome-bluetooth-ru.omf'
"
"

非开头匹配,替换所有记录
#sed -e 's/: *broken symbolic.*$/"/g' csdn_test
/usr/share/omf/gnome-bluetooth/gnome-bluetooth-ru.omf"
/usr/share/omf/gnome-bluetooth/gnome-bluetooth-ru.omf"
/usr/share/omf/gnome-bluetooth/gnome-bluetooth-ru.omf"
"
"

热点排行
Bad Request.