1

how can I combine those two lines that if any TunerParams and or Calcinternal are found only "error: Rule 19: Tunerparams and/or Calicinternal in Script at line X, Y...." is echoed

{
egrep -E "TunerParams|CalcInternal" $INPUT_FILE -n | cut -d ":" -f 1
echo "error: Rule 19: Tunerparams and/or Calicinternal in Script at line"
}
  • can you show us sample data ? – Rahul Sep 9 '16 at 11:02
4
awk '/TunerParams|CalcInternal/ {print "error: Rule 19: Tunerparams and/or Calicinternal in Script at line", NR}' $FILENAME
|improve this answer|||||
2

The awk solution from ocurran is a great one. Since you seem interested in doing it with egrep in particular, you'd have to do it in a couple of steps:

line="$(egrep -E "TunerParams|CalcInternal" "$INPUT_FILE" -n | cut -d ":" -f 1)"
if [[ -z $line ]]; then
    printf 'error: Rule 19: Tunerparams and/or Calicinternal in Script at line %s\n' "$line"
fi

which will capture the output of the egrep command, then if there was anything in that output, will print the error message, otherwise it won't print anything

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.