grep 多字符查找问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
h7054
帖子: 9
注册时间: 2014-03-08 17:38

grep 多字符查找问题

#1

帖子 h7054 » 2015-01-06 22:30

我写了个grep 多字符查找脚本 但是运行后死活没反应,请问大牛知道这是怎么回事吗?
附件
QQ图片20150106222950.jpg
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

Re: grep 多字符查找问题

#2

帖子 millenniumdark » 2015-01-07 15:05

代碼不要用圖片,還有你 mac.text 的內容也貼一下
zhangxiaofir
帖子: 53
注册时间: 2010-12-09 23:54

Re: grep 多字符查找问题

#3

帖子 zhangxiaofir » 2015-02-26 14:38

代码: 全选

[test]$ cat test.txt 
a
b
c
[test]$ cat string.txt 
a
[test]$ cat seed.sh 
while read string
do
echo "grep $string"
grep "$string" test.txt
done <string.txt
[test]$ sh seed.sh 
grep a
a
建议使用sh -x 来调试脚本 或者在必要的地方echo输出变量
infidel
帖子: 136
注册时间: 2012-03-28 10:16

Re: grep 多字符查找问题

#4

帖子 infidel » 2015-03-06 16:23

楼主把grep命令用错了吧
应该是
echo $string |grep -w -e '*.log'

楼主的意思是从string里面找log结尾的东西对吗?
回复