Is histogram matching used in real-life photo editing ? Lets say, I have 2 images and I want the first to have histogram of second. And is there any software, that can do this?
In the broadest sense (using your example rather than your actual question as a guideline), yes, there is software that will do more-or-less what you're after. Rather than direct histogram matching (which has content dependencies) one image is used as a sort of "tone template" for another image.
The package I'm most familiar with is Topaz Labs' photoFXlab, and they call their version of this approach "InstaTone". Rather than using a histogram directly, both the source and target images are frequency-separated for analysis to get a picture of the major tonalities, and the target is adjusted to fall into more-or-less the same range. It can't always work — there may be large areas of the target image that fall outside of the adjustment gamut, and some images just plain look nasty when the wrong tone template is applied. But it can be a good, quick way to get a consistent sunset look, for instance, if you have a set of "perfect" images to use as tone templates.
photoFXlab can be used as a stand-alone, or in conjunction with a RAW processor (like Lightroom) or an Photoshop-plugin-compatible image editor, and can be used as a plugin host for most 8BF-type plugins. If you're using it as a stand-alone or with LR/Aperture, it will provide you access to layers/masks without having to go to another image editor. (Not shilling and no connection; just a satisfied user of some of their other products.)
I don't think this technique is used widely if at all. Aside from giving broad information about exposure, the particular shape of the histogram is very specific to the image content, so forcing an image to conform to the histogram of a different image would be pointless and quite likely eliminate detail in certain areas.
The only possible use would be if the two images were of the same subject and you wanted to eliminate any exposure / tonecurve differences that are the result of camera settings or post processing.
The problem itself is under-constrained, since there are many different ways you could manipulate an image to get a certain histogram, so you would have to make some other assumptions such as smoothness or deviation from linearity in order to ensure a unique solution.