Valmiki Ramayana Yuddha Kanda Sarga 87 Shloka 21
Original Shlokaधर्मात्प्रच्युतशीलंहिपुरुषंपापनिश्चयम् ।।6.87.21।। त्यक्त्वासुखमवाप्नोतिहस्तादाशीविषंयथा ।
1 source checked for this shloka
धर्मात् righteous, प्रच्युतशीलम् who has renounced, पापनिश्चयम् of sinful deeds, पुरुषम् man, हस्तात् from hand, आशीविषंयथा venomous serpent, त्यक्त्वा renouncing, सुखम् happiness, अवाप्नोति attains
"The association of one who has renounced righteousness and is of sinful deeds is left by a righteous man who undoubtedly attains happiness, is like shaking of a venomous serpent from the hand."