Simplified Code? Acceptable?

Hi Folks -

I have the following peice of code that I believe is uncecesarily long and I modified it to shorten it up. I was hoping one could comment and confirm my approach was acceptable?

Original:

    if [ -n "$_FDMEE_ERR" ]
    then
        pushd "${_INTRAPATH}"
            #Search for lines in the log where the Unmapped Member Rules come back with a value > 0
            #Unmapped_Department, Unmapped_Product, Unmapped_Account, Unmapped_Entity, Unmapped_SubEntity
            
            if grep -q "'UnmappedDepartmentRule' (LIKE): [^0]" "${_FDMEE_LOG}"; then
                echo "There are members mapped to 'Unmapped_Department'" >> "${_REPORT}"        
            fi
                
            if grep -q "'UnmappedProductRule' (LIKE): [^0]" "${_FDMEE_LOG}"; then    
                echo "There are members mapped to 'Unmapped_Product'" >> "${_REPORT}"    
            fi
                
            if grep -q "'UnmappedAccountRule' (LIKE): [^0]" "${_FDMEE_LOG}"; then    
                echo "There are members mapped to 'Unmapped_Account'" >> "${_REPORT}"        
            fi
                
            if grep -q "'UnmappedEntityRule' (LIKE): [^0]" "${_FDMEE_LOG}"; then    
                echo "There are members mapped to 'Unmapped_Entity'" >> "${_REPORT}"        
            fi
                
            if grep -q "'UnmappedSubEntityRule' (LIKE): [^0]" "${_FDMEE_LOG}"; then    
                echo "There are members mapped to 'Unmapped_SubEntity'" >> "${_REPORT}"        
            fi
            
            if grep -q "${_SEARCH}" "${_FDMEE_LOG}"; then
                echo " ">> "${_REPORT}"; echo "Kickouts Below:" >> "${_REPORT}"
                grep -w "${_SEARCH}" "${_FDMEE_LOG}" >> "${_REPORT}"    
            fi
            
            if [ -f "${_REPORT}" ]
            then
                sed -i '1 i\Review Data Management console to view unmapped members' "${_REPORT}"
                sed -i '2 i\Add unmapped members to the hierarchy and then rerun the data load' "${_REPORT}"
                sed -i '3 i\ ' "${_REPORT}"
                mailx -s "ATTENTION: Unmapped Members/Kickout Report [DLR - ${_DLR}]" name@name.com < "${_REPORT}"    
            fi
    fi

New:

    if [ -n "$_FDMEE_ERR" ]
    then
        pushd "${_INTRAPATH}"
            #Search for lines in the log where the Unmapped Member Rules come back with a value > 0
            #Unmapped_Department, Unmapped_Product, Unmapped_Account, Unmapped_Entity, Unmapped_SubEntity
            
            for _DIM in Department Product Account Entity SubEntity
            do
                if grep -q "'Unmapped${_DIM}Rule' (LIKE): [^0]" "${_FDMEE_LOG}"; then    
                    echo "There are members mapped to 'Unmapped_${_DIM}'" >> "${_REPORT}"    
                fi            
            done
            
            if grep -q "${_SEARCH}" "${_FDMEE_LOG}"; then
                echo " ">> "${_REPORT}"; echo "Kickouts Below:" >> "${_REPORT}"
                grep -w "${_SEARCH}" "${_FDMEE_LOG}" >> "${_REPORT}"    
            fi
            
            if [ -f "${_REPORT}" ]
            then
                sed -i '1 i\Review Data Management console to view unmapped members' "${_REPORT}"
                sed -i '2 i\Add unmapped members to the hierarchy and then rerun the data load' "${_REPORT}"
                sed -i '3 i\ ' "${_REPORT}"
                mailx -s "ATTENTION: Unmapped Members/Kickout Report [DLR - ${_DLR}]" name@name.com < "${_REPORT}"    
            fi
    fi

Thanks!

On first sight the "new" looks like being equivalent. Still you're running grep five times, and opening ${_FDMEE_LOG} seven times. It might be worthwhile to consider a small awk script.