A sputum sample is the traditional method of determining the type of infectious organism, however if you cough up one it is likely to be contaminated so they prefer to insert a probe into the trachea and thence into the lung. The substance extracted is then cultured. Since this procedure is expensive and hazardous modern physicians usually only prescribe broad-scope antibiotics.
The usual presentation of a bacterial infection in the lung is yellow or greenish sputum.