linux shell grep命令单字匹配

阅读 4

2024-09-02


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)

0 0 举报