There are 2 ways I recommend going about this.
1) Put a function in your bashrc / bash_profile and create an alias to call that function (this will make global usage of this)
2) create a shell script file and can create an alias of that file as well.
#!/bin/bash
function matchString(){
REGEX="$1"
FILE="$2"
RESULTS=$(grep -n "$REGEX" $FILE | awk -F ":" '{print $2 "\tLine: " $1}')
COUNT=$(echo $RESULTS | wc -l)
echo "Count: $COUNT"
echo $RESULTS
}
matchString $1 $2
Calling this file (ie. bash matchString.sh "abc-ERROR:" test.txt) based on your text file will output as this:
Count: 1
abc-ERROR Line: 1
--This function takes 1st arg as the regex pattern (so this can be re-used in any similar scenario) and searches that pattern in the file which is called by the 2nd arg.
1st line of output is the total count of all matched lines, and each line after is the match followed by a tab a line number of that match.