开发者

Shell script string search where '#' is not in 1st character position

this string search was provided by Paul.R (much appreciated Paul):

** find dir -type f -print0 | xargs -0 grep -F -f strings.txt **

Note, I am using the above search argument to perform a recursive directory search for hard coded path names within shell scripts. However, due to the limitations of the Unix environment (TRU64) I am unable to use the GREP -r switch to perform my directory search. Hence the use of the solution provided above.

As an additional criteria, I would like to extend this search argume开发者_开发百科nt to exclude any text where the first leading character of the string being searched is "#" (comment symbol).

Would appreciate any feedback.

Thanks...Evan


I'm assuming you're just trying to limit the results in the output from the command you posted. If that's so, then how about

find dir -type f -print0 | xargs -0 grep -F -f strings.txt | grep -v '^#'

The final piped command will ignore all lines that match the regex ^# (begins with # char)


This solution will not work if the path and file of the files is contained in strings.txt, but it might work in your situation.

find dir -type f -print0 | xargs -0 grep -v '^#' | grep -F -f strings.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜