Monday, November 1, 2021

[SOLVED] bash: make the grep command to ignore line with certain special characters $(

Issue

Hi I am trying to make the grep ignore line with certain special characters $(

Input:

/XGenerator.mk:98:LOCAL_MODULE := filesxml.sh
/XGenerator.mk:106:LOCAL_MODULE := doublefiles.sh
/LibParameter.mk:35:LOCAL_MODULE := libparameter$(SUFFIX)
/LibUtility.mk:35:LOCAL_MODULE := libpfw_utility$(SUFFIX)

Expected output:

/XGenerator.mk:98:LOCAL_MODULE := filesxml.sh
/XGenerator.mk:106:LOCAL_MODULE := doublefiles.sh

My try1

grep -Rin "LOCAL_MODULE :=" --include="*.mk" | grep -v '$('

not working

My try2

grep -Rin "LOCAL_MODULE :=" --include="*.mk" | grep -v '/$/('

not working

Please can anyone help ?


Solution

You should use a logic OR in your grep command

grep -Rin "LOCAL_MODULE :=" --include="*.mk" | grep -v '\$\|('

Explanation:
The -v flag exclude line matching the pattern, as you already know. The $ character need to be escaped, as well as the OR special character |.



Answered By - franzisk