how would i write a shell script to show the number of lines in which int variable appears in a c++ program.
how would i do this using cut or awk methods is it possbile and having a output similar to this
x, number of apperances =
y, number of apperances =
jaduks
2
A non-awk one
f_count() {
WHAT=$1
FILE=$2
echo "$WHAT, number of apperances = `grep -c "\<$WHAT\>" $FILE`"
}
f_count x myc.cpp
f_count y myc.cpp
$ sh occ.sh
x, number of apperances = 2
y, number of apperances = 3
//Jadu
jaduks
3
$ awk '/\<x\>/ {++c} END {print c}' myc.cpp
2
$ awk '/\<y\>/ {++c} END {print c}' myc.cpp
3
//Jadu