This is a fairly common problem that happens when the derailleur cable gets past its sell-by-date. Only a small amount of deterioration in the condition of the cable is needed to make shifting less than perfect. If the bike has been in storage for a while then a localised patch of oxidation can set in to affect one bit of the shifting range, where this is depends on what gear the bike was last used in. You can also get a kink in the cable that might have been made when the bike was initially setup. Such a kink will also give unpredictable results.
You can pop the cable out and give it a lube to see if that fixes the problem. Put the chain on the big sprocket and then shift the lever to the position for the little sprocket but without pedalling. This will give maximum slack. The cable guides on the frame should have little slots in them, you can now pull the outers out and be able to move the outers up and down on the inners. Be careful to not bend the inner if doing this. Give the inners a good clean with 'GT85' or other water-displacing light lube, make sure everything is clean and put it all back together again. You now need to make sure that the outers are all of the way in on the cable stops, stress the inner a bit to do this by pulling the inner.
Give the bike another test but expect problems to persist or be even worse. If this has not fixed the problem go straight for a new cable inner and outer. A new cable will be silky smooth, however, this will require tools to cut the cable outers to length and shape the ends nicely. Plus you don't want the inner to have a frayed end. Your regular pliers just won't cut it. If you cannot borrow a nice pair of Shimano cable cutters, take it into a bike shop and get them to do it for you.
With a new kink-free and corrosion free cable your gear changes will be a lot smoother and index properly.
It is unlikely that grime on the derailleur or sprockets is the cause of the problem. Even if the derailleur wheels and sprockets are solidly built up with gunk this should not affect shifting. This is more likely to result in the gears slipping (but staying in gear rather than not indexing across the range).
It is also highly unlikely that you have bent teeth on the sprockets, if you did then you would not be able to ride '6' at all, which you can if the indexing lets you do it.
To summarise, the magic bullet here is a new cable. You can try to clean up the existing cable and that might work, however, putting in a new cable will save you a lot of time and give you gears that are a joy to use.