In all most all situations the spear is superior to the sword
Is there eny specific weapon to counter the spear?
Hang on. The spear is not at all superior to the sword in almost all situations. The reason the spear has been such a popular weapon throughout history is a combination of many factors. First of all the spear is cheap and easy to make in large quantities, it is after all just a pointed stick. Second it has a great advantage in formations because it can reach the edge of the formation from the second and sometimes even third. Finally it is very intuitive to use, just "stick 'em with the pointy end". However, one handed weapons has advantages too. They are much more useful in a disorganized fight, can we wielded in cramped situations and it can attack from many more angles than a spear. An example is defending fortifications when formation fighting is not really a thing, another is fighting on broken ground where maintaining formation is difficult or impossible.
So how do you counter a spear? Well, there are many ways to do it. A pike is one good example, in formation fighting the longer pointed stick has an advantage. The macedonian phalanx use of the sarissa is a great example. At nearly 18 ft in length even the fifth row can reach beyond the formation edge and the second row sarissas will easily out-range any normal spear. Mobile spear formations are also liable to be out-flanked or out-maneuvered by faster moving infantry. A spear formation is strong when presenting a spear wall to the enemy or when in square formation (essentially presenting 4 separate spear walls) but it is a relatively slow formation to rotate, this is especially true for non-professional soldiers such as levied troops or various forms of militia. If attacked in the flank, when turning or when disorganized a spear formation is at a decided disadvantage against an infantry formation with shorter one handed weapons. The spanish use of rodeleros in the Italian wars in the early 16th century is a great example of that. A spear formation is also typically relatively vulnerable to mobile skirmishers and heavy weapons or, in the gunpowder era, musket or cannon fire. This is especially true for spearsmen and pikemen since their tactics to a greater degree than most other forms of infantry relies on close formations giving the unit weight.
There are also more specialized ways to deal with spears and pikes, the Landesknechte doppelsöldner are one such example. Equipped with large two handed swords these men specialized in attacking opposing spear/pike formations, exactly how is unknown to this day but the two main theories are that they either employed a tactics based on sweeping enemy spears aside/cutting them off or in quickly closing with the spear formation to get "behind" the spearheads where a spearmen is at a disadvantage. Either one is about equally likely in my personal opinion but the fact that the practice remained in use for a long time suggests that it was effective regardless of exactly which strategy they employed. The Swiss pike formations employed halberdiers to similar effect and the spanish used previously mentioned rodeleros to either break spear formations or out-flank them when locked in "push-of-pike" type combat. Cavalry has also historically proved the bane of spear formations if they can hit them in the flank or from behind (any unit will do that but a cavalry unit is just more likely to do it thanks to their greater mobility on the battlefield).
The spear owes it's popularity primarily to the factors listed above, as a consequence of that spearmen were a relatively easy unit to field en masse. This in turn led to battlefield tactics centered around the use of spears for a long, long, time but they are by no means unbeatable, they're just very cost effective and in the end, war is just a pissing contest of national economics. Whoever can piss away the most or make the most of what they piss away wins.
Since u/Superplaner has already discussed the spear on the battlefield in detail, I'll only briefly discuss the battlefield. The general advantage of the spear is reach. Apart from longer spears, missile weapons allow one to hit a spearman while staying out of reach. For example, the Spartans were defeated by light troops armed with missiles at Lechaion and Sphakteria, as described by u/Iphikrates in https://www.reddit.com/r/AskHistorians/comments/4bm2l1/why_didnt_light_infantry_massively_prevailed/ Second, the importance of reach is diminished by armour (and shields) - the probability of an opponent getting the first chance to hit matters less if they are less likely to do any damage with the hit.
As for the spear off the battlefield, we can note some disadvantages: a spear is much less convenient to carry than a sword, and a spear can be much harder to use indoors or in some other confined space. One method of countering a spear is to fight where the opponent can't easily take or use their spear.
Some people imagine that it is easy to defeat a spearman, that one can simply parry and get past the spear point (and that the spear is then useless), or that one can easily grab the spear haft. These imaginings neglect a second advantage of the (two-handed) spear: speed. The leverage of a two-handed grip makes a spear very mobile (unless it is very long and heavy), and such feats are much, much harder in reality than imagination. In particular, if a spear is parried, the spearman can very quickly disengage and renew the attack, preventing the opponent from getting in close. Thus, if one is designing weapons to use against a spear, it is important to stop such quick disengagement. Some features/weapons that can do this:
Shorter spears with parrying bars (e.g., Japanese yari with hadome, partisans, etc.) or other polearms with suitable spikes/hooks that can reduce the mobility of an opponent's spear.
The use of two weapons (e.g., two swords). Chinese twin sword forms/kata have many techniques that are designed for use against spears. At the core of many of these is the idea that one sword parries, and the other accompanies it to stop the disengagement. This can also be achieved without needing to wait for an attack to parry, simply by actively trying to trap the spear. (One weapon that combines both 1 and 2 is the Chinese hook sword (used in pairs).)
Very long cross-guards on swords.
Weapons with features like these are not necessarily "better" than a spear. For example, if a polearm with a spiked/hooked head is too heavy, the speed of the spear might still leave the spear with a significant advantage, and a long cross on a sword is usually insufficient for advantage. Often, these are simply things that reduce how much more skilled one must be to have a good chance of defeating a spear-armed opponent.
Of course, ranged weapons and armour help off the battlefield as well as on.
Thank you u/superplaner and u/wotan_weevil i really appreciate Your effort in Your opinion and knowledge