Home

Resources

Login Form



 
Welcome to the Frontpage
首页
技术文章 - php
Written by Administrator   
Wednesday, 07 July 2004 11:54

 


php

dotnet


  
  
  
  
  
  
  
  
  
  
  

{php}echo 'this is code';{/php}

 

Last Updated ( Monday, 19 May 2008 20:43 )
Read more...
 
newwork: Hello_world_
技术文章 - WEB2.0
Tuesday, 23 September 2008 01:00

Welcome to My.donews.com. This is your first post. Edit or delete it, then start blogging!

Read more...
 
Linux shell脚本区别内容相同的文件.
技术文章 - WEB2.0
Written by Administrator   
Thursday, 25 September 2008 22:00

{mm random=news,(title)}

Linux shell脚本区别内容相同的文件. - 开源 - CSDN技术中心 以前使用'网络蜘蛛'抓取了不少文件.但后来发现这些文件中有很多是内容完全相同的,如何只保留一份内容相同的文件而把其它相同的去除掉哪?我使用了linux shell脚本处理这个问题: 以前使用'网络蜘蛛'抓取了不少文件.但后来发现这些文件中有很多是内容完全相同的,如何只保留一份内容相同的文件而把其它相同的去除掉哪?我使用了linux shell脚本处理这个问题: for file in * #遍历文件 do if ! [ -f "$file" ] #如果文件存在的话,因为有的文件可能被剔除了. then echo $file" not exist" ...

Last Updated ( Saturday, 15 March 2008 13:26 )
Read more...
 
newwork: Linux_shell脚本区别内容相同的文件.
技术文章 - WEB2.0
Thursday, 25 September 2008 21:00

Linux shell脚本区别内容相同的文件. - 开源 - CSDN技术中心

以前使用’网络蜘蛛’抓取了不少文件.但后来发现这些文件中有很多是内容完全相同的,如何只保留一份内容相同的文件而把其它相同的去除掉哪?我使用了linux shell脚本处理这个问题:

以前使用’网络蜘蛛’抓取了不少文件.但后来发现这些文件中有很多是内容完全相同的,如何只保留一份内容相同的文件而把其它相同的去除掉哪?我使用了linux shell脚本处理这个问题:

for file in * #遍历文件
do
if ! [ -f “$file” ] #如果文件存在的话,因为有的文件可能被剔除了.
then
echo $file” not exist”
else
for i in *
do
if [ “$file” != “$i” ] #如果文件名不同
then
if cmp -s $file $i
then
mv $i ../same/
fi
fi
done
mv $file ../unique/
fi
done

我一共处理4000多个文件,运行的挺慢的,用了1天零2夜才处理完,我汗,竟剔出了近2000,我再汗.

为了提高效率,后来考虑只对文件大小相同的文件才进行比较.脚本如下:

for file in * #遍历文件
do
if ! [ -f “$file” ] #如果文件存在的话,因为有的文件可能被剔除了.
then
echo $file” not exist”
else
leno=`ls -l $file | awk ‘{print $5}’` #使用ls和awk提出文件大小
for i in *
do
leni=`ls -l $i | awk ‘{print $5}’`
if [ “$file” != “$i” -a “$leno” = “$leni” ] #如果文件名不同,并且文件大小相同
then
if cmp -s $file $i
then
mv $i ../same/
fi
fi
done
mv $file ../unique/
fi
done

找了一小部分文件测试了一下,速度竟比第一个还慢,可能是频繁调用ls和awk的问题.
先到此,如果有更好的办法,再作补充.

Read more...
 
 

Who's Online

We have 145 guests online