Chinaunix

标题: shell问题请教!<具体问题见内容> [打印本页]

作者: lyfire    时间: 2004-03-18 17:01
标题: shell问题请教!<具体问题见内容>
如何通过shell程序查找一个文本中是否含有字符串
如果
有: 计数器 + 1
没有: 在查是否有下一个字符串

主要是 如何处理 yes or no 的判断呢?
作者: 零二年的夏天    时间: 2004-03-18 17:12
标题: shell问题请教!<具体问题见内容>
可以判断程序是否执行,有一个变量可以判断的。
作者: 零二年的夏天    时间: 2004-03-18 19:05
标题: shell问题请教!<具体问题见内容>
$? 可以检测程序是否执行成功,不知对楼主是否有帮助。
作者: eagerlinuxer    时间: 2004-03-18 21:26
标题: shell问题请教!<具体问题见内容>
[root@wy1 tmp]# cat aaa
iiiii
iiii
iii
ii
i
oo
ooo
oooo
[root@wy1 tmp]# cat aq
ii
oo
[root@wy1 tmp]# cat finds.sh
#!/bin/bash
let sum=0
while read words
do
  if cat aaa | grep $words &>; /dev/null;then
    let sum=$sum+1
  fi
done < aq
echo $sum
[root@wy1 tmp]# bash finds.sh
2
[root@wy1 tmp]#
作者: lyfire    时间: 2004-03-19 11:15
标题: shell问题请教!<具体问题见内容>
谢谢!楼上各位!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2