bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#56888: 'echo message | grep []' is affected by files in local direct


From: H3rm1t
Subject: bug#56888: 'echo message | grep []' is affected by files in local directory when using bracket
Date: Tue, 2 Aug 2022 16:13:17 +0800

  Hi:
 I use grep to search string in a message like this.

> [root@office tmp]# echo "axyz" | grep [abcd]xyz
> axyz
> [root@office tmp]# echo "cxyz" | grep [abcd]xyz
> cxyz
> [root@office tmp]# echo "bxyz" | grep [abcd]xyz
> bxyz
> [root@office tmp]# echo "dxyz" | grep [abcd]xyz
> dxyz
> [root@office tmp]# echo "oxyz" | grep [abcd]xyz
> [root@office tmp]#
>
but I find something strange ,when I create a file with special name in
current diretory, the command execute failed:

> [root@office tmp]# touch axyz
> [root@office tmp]# echo "bxyz" | grep [abcd]xyz
> [root@office tmp]# echo "cxyz" | grep [abcd]xyz
> [root@office tmp]# echo "dxyz" | grep [abcd]xyz
> [root@office tmp]# rm axyz
> rm: remove regular empty file 'axyz'? y
> [root@office tmp]# echo "bxyz" | grep [abcd]xyz
> bxyz
> [root@office tmp]# echo "cxyz" | grep [abcd]xyz
> cxyz
> [root@office tmp]# echo "dxyz" | grep [abcd]xyz
> dxyz
>
I dont know why? Is it a feature or a bug?

And another problem, when the files number is too big in directory, the
grep with bracket execute slow perfermance:

[root@office tmp]# cd greptest/
> [root@office greptest]# ls -l | wc -l                #this dir has 50000
> files
> 50001
> [root@office greptest]# time echo "axyz" | grep [abcd]xyz
> axyz
>
> *real 0m0.014s*
> user 0m0.007s
> sys 0m0.008s
> [root@office greptest]# time echo "axyz" | grep [abcd]xyz
> axyz
>
> real 0m0.013s
> user 0m0.003s
> sys 0m0.010s
> [root@office greptest]# time echo "axyz" | grep [abcd]xyz
> axyz
>
> real 0m0.014s
> user 0m0.007s
> sys 0m0.008s
> [root@office greptest]# cd ..     # go to upper dir with small number of
> files
> [root@office tmp]# time echo "axyz" | grep [abcd]xyz
> axyz
>
> *real 0m0.003s*
> user 0m0.001s
> sys 0m0.003s
> [root@office tmp]#
>
      if I don't use bracket regex, the perfermance in dirs with different
number of files are similer.

      in my mind,  the cmd like ( echo message | grep [abcd]efg )
is uncorrelated with local filesystems
but I dont know what happened in this 2 cases. It seems grep do something
with filesystems
why and how to avoid it?

      Thank you very very much

-- 
H.Huang


reply via email to

[Prev in Thread] Current Thread [Next in Thread]