Simplified Code? Acceptable?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Simplified Code? Acceptable?
# 1  
Old 11-13-2018
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:


Code:
    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:



Code:
    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!
# 2  
Old 11-13-2018
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Simplified Registration Page with nCaptcha

At Ravinder's request, I have simplified the new member registration page on both mobile and desktop: Mobile: https://www.unix.com/members/1-albums214-picture909.jpeg Desktop (big image): https://www.unix.com/members/1-albums215-picture907.png (2 Replies)
Discussion started by: Neo
2 Replies

2. What is on Your Mind?

New Simplified Log Out for UNIX.COM

Hi, I changed the logout code to just simply log out and go back to the page you were viewing: Was (ending code): eval(standard_error(fetch_error('cookieclear', create_full_url($vbulletin->url), $vbulletin->options, $vbulletin->session->vars), '', false)); Now: $goto = "Location:... (0 Replies)
Discussion started by: Neo
0 Replies

3. Shell Programming and Scripting

Simplified file conversion

Hi All, I have a file like below Topic:price PartitionCount:5 ReplicationFactor:3 Configs: Topic: price Partition: 0 Leader: 13 Replicas: 13,15,11 Isr: 11,13 Topic: price Partition: 1 Leader: 14 Replicas: 14,11,12 Isr: 11,12,14 ... (4 Replies)
Discussion started by: manas_ranjan
4 Replies

4. UNIX for Beginners Questions & Answers

Using exit in For Loop - Is this acceptable

Hi Folks - Here is a for loop I've created and I just wanted to see if this was okay practice: for M in NAME1 NAME1 NAME3 do echo "Executing MaxL:" $M >>${_LOGFILE} 2>&1 . ${_STARTMAXLPATH}startmaxl.sh ${_MAINPATH}${_MAXLPATH}$M.mxl _RC=$? if then ... (7 Replies)
Discussion started by: SIMMS7400
7 Replies

5. Shell Programming and Scripting

Simplified awk script for if else statements

Hi, The below awk script that i did is working fine. It gives me the results that i want. But, the script is not smart and very long as i have 8 conditions to meet. The sample script below only show 2 conditions. awk 'BEGIN{FS=OFS=" ~ |\t"} {if (($7>$9) && ($6>$8)){ Ql= $7-$6; Sl=... (6 Replies)
Discussion started by: redse171
6 Replies

6. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

7. Solaris

configure: error: no acceptable ld found in $PATH

When i configure apache(2.2.15) on solaris-8 server it producing following error <configure: error: no acceptable ld found in $PATH configure failed for srclib/apr > please help me any to fix this error. :confused: ---------- Post updated at 09:44 PM ---------- Previous update was... (0 Replies)
Discussion started by: kalpeer
0 Replies

8. Post Here to Contact Site Administrators and Moderators

Link to Amazon wishlist or similar, acceptable?

A guy contacted me a while back and wanted to compensate me for helping him with a question here in the forums. I never heard back from him, but I said I would create an Amazon wishlist and link to it from my profile. Only now do I realize that this is something the forum owners might have an... (2 Replies)
Discussion started by: era
2 Replies

9. HP-UX

printer problem - 10.48.2.24 is NOT an acceptable name

HP-UX 10.20 with an HP LaserJet P2015dn. I've connected and configured the P2015 using its internal nic on our Win 2003 Server network. When trying to add it to UNIX thru sam, network based printer plotter --> add printer/plotter connected to hp jetdirect --> add printer to local spooler, I... (3 Replies)
Discussion started by: mtedeschi
3 Replies

10. IP Networking

Acceptable collisions

Hi All I have a Sun V120 with eri0 NIC set to 10-Half connected to Fa0/0 on a Cisco 2600 (Fa0/0 also set to 10-Half). I am seeing collisions on this link (as expectd with a 10-Half connection) BUT, what is an acceptable rate of collisions for this type of link? FYI, the Sun box is showing... (2 Replies)
Discussion started by: bashdem
2 Replies
Login or Register to Ask a Question