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 ~]#
标签:shell,grep,echo,sh,file,linux,output,22222
From: https://blog.51cto.com/ztj1216/11899541