It certainly occurred, but it wasn't something a wise general or officer needed to factor into his battle plans. Seldom if ever was it a decisive factor in an engagement.
Veterans often joked that bayonets were more useful as cooking/eating utensils, entrenchment tools, even candle-holders, than they were as weapons. If I recall correctly, less than 1% of combat wounds were inflicted with bayonets. Of course, even in earlier centuries the bayonet seemed to have been more of a psychological than a physical weapon.
Edged weapons were still very much in the military mindset at the beginning of the Civil War. The famous abolitionist John Brown murdered several slave-owners with broadswords, and intended to equip his slave army with pikes. At the start of the War, all officers and many privates carried edged weapons with them. These ranged from gorgeous dress sabers, to crude bowie knives (the latter being a Confederate favorite in 1861).
Sabers were issued to most cavalry units on both sides, but like bayonets they tended to be used for decidedly non-lethal purposes, or discarded altogether. Nonetheless, there are a number of accounts of cavalrymen using sabers to good effect. The ruthless Confederate general Nathan Bedford Forrest killed several Northern men with his saber, and saber wounds were inflicted during the cavalry actions at Brandy Station and Gettysburg.
The 6th PA Volunteer Cavalry, known as 'Rush's Lancers', were originally equipped with spears and sabers. Despite the aura of romance surrounding this arsenal, the men of the regiment proved incompetent in melee combat. During one episode in the Peninsular Campaign, a unit of Confederates reportedly burst into a fit of hysterical laughter when the 6th Cavalry attempted to attack them. Eventually, they were issued carbines - and shortly thereafter, scored their first kills of the War.
There are many individual accounts of melee combat. At Gettysburg, in the Overland Campaign, and elsewhere, soldiers often preferred to bludgeon each other with rifle-butts rather than attempt to stab with bayonets. The famous military artist Don Troiani painted a scene, commemorating an incident during the Siege of Petersburg when an officer in a Vermont regiment killed a Rebel with his saber, and won the Medal of Honor as a result.
Some of the most terrible melee combat of the War took place at the Bloody Angle, during the series of battles around Spotsylvania Courthouse in May of 1864. One Union veteran recalled men attacking each other with rifle butts, bayonets, sabers, bowie knives, wood-chopping axes, and rocks. At Second Manassas, one Confederate brigade ran out of ammunition and held off a Union assault by hurling rocks.