Issue
I have below parameter that needs to be checked if it is available in a file.
PARAMS='SQLNET.INBOUND_CONNECT_TIMEOUT>=45'
how can i check for the occurrence of the above listed parameter in a file such that the count is 1 if it is available in the file.Also to note that it is ok to have spaces before and after the '>='.
i have the below code :
PARAM_COUNT=`cat file_name | tr -d "[:blank:]" |awk '$1 ~ /^[^;#]/' | grep -i ${PARAM} | wc -l`
Please suggest what modification is necessary.Thanks.
Solution
- The awk is not needed because grep will do the reg exp
- The
wc -l
is not needed because grep can count too
cat input | tr -d '[:blank:]' | grep -c "^PARAMS='SQLNET.INBOUND_CONNECT_TIMEOUT>=45'"
Please note the ^
to indicate that the text should be found at the start of the line.
Or:
grep -c "^[[:blank:]]*PARAMS='SQLNET.INBOUND_CONNECT_TIMEOUT[[:blank:]]*>=[[:blank:]]*
45'" input
Answered By - Luuk Answer Checked By - David Marino (WPSolving Volunteer)