0
点赞
收藏
分享

微信扫一扫

linux shell grep命令单字匹配


grep.sh

#!/bin/bash

E_BADARGS=65

if [ -z "$1" ];then
  echo "Usage:`basename $0` pattern"
  exit $E_BADARGS
fi

echo

for file in *
do
  output=$(sed -n /"$1"/p $file)
  if [ ! -z "$output" ];then
    echo -n "$file: "
    echo $output
  fi
done

exit 0

验证:

[root@logstash ~]# sh grep.sh 22222

1.txt: 22222
2.txt: 22222
[root@logstash ~]#

举报

相关推荐

0 条评论