Chinaunix首页 | 论坛 | 博客
  • 博客访问: 217683
  • 博文数量: 57
  • 博客积分: 1376
  • 博客等级: 中尉
  • 技术积分: 658
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-09 09:51
文章分类

全部博文(57)

文章存档

2012年(1)

2011年(56)

分类: LINUX

2011-03-06 16:25:51

Today, in order to find a scott schema, I wrote a script to do  it.

  1. #!/bin/bash
  2. # This script is used to find the specific content from target directory
  3. # Author: Milo
  4. # $1 will be the target path
  5. # $2 will be the keyword you want to search in the target file.

  6. #Pass the target path to variable
  7. TAR_DIR=$1
  8. #Pass the target keyword to variable
  9. KEYWORD=$2
  10. #Max depth
  11. MAX=10

  12. for f in $(find $TAR_DIR -maxdepth $MAX )
  13. do
  14.         if [[ -d $f ]]
  15.         then
  16.                 grep -n $KEYWORD $f/* --color 2> /dev/null
  17.         else
  18.                 grep -n $KEYWORD $f --color 2> /dev/null
  19.         fi
  20. done

Hope it will help me some days.
阅读(2468) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~