LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1514|回复: 2

一个从文本文件生成黑客字典的脚本

[复制链接]
发表于 2005-12-15 22:58:33 | 显示全部楼层 |阅读模式
基本功能与windows中的txt2dic.exe类似,代码如下:
  1. #!/bin/sh
  2. #name: txt2dic.sh
  3. #useage: txt2dic.sh file1 file2
  4. error()
  5. {
  6. echo "usage:`basename $0` file1 file2"
  7. exit 1
  8. }
  9. if [ $# -lt 2 ]; then
  10. error
  11. exit 1
  12. fi
  13. if [ ! -f $1 ]; then
  14. echo "$1 is not a file"
  15. error
  16. fi
  17. if [ -s $2 ]; then
  18. echo "$2 already exist"
  19. error
  20. fi
  21. while read line
  22. do
  23.    newline=`echo $line|tr -cs "[:alpha:]" " "`
  24.    word=`echo $newline|wc -w`
  25.    i=1
  26.    while [ "$i" -le "$word" ]
  27.     do
  28.       echo $newline|awk '{print $i }'|tr -s "[:blank:]" "\n" >> $2
  29.       i=`expr $i + 1`
  30.     done
  31. done < $1
  32. sort -u -o $2 $2
复制代码
发表于 2005-12-16 09:00:40 | 显示全部楼层
不需要写脚本吧

只要字母的
  1. tr -cs '[:alpha:]' '[\n*]' <file1 >>file2
复制代码

字母加数字的
  1. tr -cs '[:alnum:]' '[\n*]' <file1 >>file2
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-12-18 15:03:55 | 显示全部楼层
Post by r2007
不需要写脚本吧

只要字母的
  1. tr -cs '[:alpha:]' '[\n*]' <file1 >>file2
复制代码

字母加数字的
  1. tr -cs '[:alnum:]' '[\n*]' <file1 >>file2
复制代码


cut -c1-10 /dev/urandom
更快些吧~_~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表