首页 > 代码库 > sed

sed

sed ‘s/^/\//g‘ 4  行首增加指定字符




提取网页中的播放地址:


#!/bin/bash
printf "enter your dir:"
read dir
echo "$dir is xx"
cd $dir
echo `pwd`
for file in `ls .`
  do
 if [ -d $file ]; then
        echo $file
        cd $file
        echo `pwd`
        tree `pwd` |grep play |sed ‘s/.* //g‘>11
        tree `pwd` |grep play |sed ‘s/.* //g‘|awk -F "-" ‘{print $2}‘ >22
        paste -d "/" 22 11 > 33
#       echo "hello"
         sed ‘s/play.html-/zzz/g‘ 33 |sed ‘s/.htm//g‘|sed ‘s/zzz/play.html?/g‘ > 44
        cat 44| sed ‘s#^#http://‘${dir}‘/‘${file}‘/#g‘ > list.txt
            cat list.txt >> /root/$dir.txt
  fi
 cd ..
  done

删除已处理的播放地址:

#!/bin/bash
printf "enter your dir:"
read dir
echo "$dir is xx"
cd $dir
echo `pwd`
for file in `ls .`
do
 if [ -d $file ]; then
        cd $file
        tree `pwd` |grep play |sed ‘s/.* //g‘|awk -F "-" ‘{print $2}‘|sed ‘s#^#/home/test/www.qqq.com/‘${file}‘/#g‘ > 1.txt
        for line in `cat 1.txt`
   do
         `/bin/rm -rf $line` > /root/del.txt
        echo "hello"
  done
        fi
 cd ..
done


循环批量替换目录下的文件:

find . -name index.htm|sed ‘s/\(.*\/\)\([0-9]\+\)\(.*\)\(index.htm\)\(.*\)/mv \1\2\3\4\5 \1\2\3play.html?\2-0-1/g‘|sh


本文出自 “hyf” 博客,请务必保留此出处http://hanyunfei.blog.51cto.com/6531994/1405182