Why are there gaps between two lines of iron filings in a magnetic field? I mean if the magnetic field is slightly increasing or decreasing at a place should'nt there be a gradient of iron filings instead of clear lines?
As to me clear lines mean that there is a comparatively strong magnetic area next to a weaker one hence the iron filings are more attracted to that particular area hence forming a line.
 A: The magnetic field originating from a bar magnet is continuously decreasing when moving away from the bar magnet. It does not have "lines" of stronger field strength. The lines that are forming are a consequence of the magnetic fields generated by the iron fillings themselves.
An iron particle possesses a magnetic moment that aligns with the magnetic field of the bar magnet. The magnetic moment of the particle also generates a magnetic field around it (just as the bar magnet does). Now, two factors of this field are important in the explanation of the lines:

*

*The magnetic field generated by the particle has an opposite direction with respect to the field of the bar magnet (on the sides of the iron particle). Hence, in the region besides the particle, the net field is reduced.

*The field generated by the particle (near field) decays faster than the field of the bar magnet (far field). Therefore, after some distance, the reduction of the net field due to the particles is neglectable.

These two arguments combined, explain the iron particle lines. If more particles are added, they will not nest themself in the region besides the already present particles because the field is weaker there. Instead, they will nest themselves somewhat further (in a new line) where the influence of the field of the iron particles is neglectable. As a result, iron particle lines are formed.
A: Self interaction of the iron filings is a valid explanation however the void-gaps  are there but not of the size scale you may think.  Quantum electrodynamics and their consequent macroscopic classical electromagnetic phenomena is discrete in nature phenomena and vacuum void space is part of the equation. Thus  coherent distortions  in quantum field cannot be continuous. It may look at such at the macroscopic classical scale but it is not. Even water flow in a river consists at the microscopic level of coherent flow streams of of Hydrogen and Oxygen atoms separated by vacuum space between them inside the water molecule and molecules in a stream are also separated by vacuum gaps (i.e. bear in mind that inside any materiel at atomic and subatomic size scales there is no medium between two atoms but only vacuum space).
Electromagnetic flux is coherent streams of virtual photons linked to electrons and void space is always there between them at least at the Plank length scale. So the physical description of a magnetic field and its magnetic flux consisting of what may seem at the macroscopic level of "countless" but still finite number of coherent stream lines of these virtual photons, carriers of the the EM force is valid and actually true.
Therefore, examining the isolated H field of a permanent magnet placed in a vacuum environment,  assuming there are no iron filings present or any other magnetic matter except the permanent magnet, the vacuum gaps between the different discrete streams of flux (i.e. flow of energy) are physically there but there are so small that at the macroscopic classical scale we observe the magnetic flux as a continuous field.
The quantum world consists manly of void vacuum gaps and is elementary discrete and this also applies for the magnetic flux of a magnetic field. The only physical entity that today is not being resolved of being discrete phenomenon is vacuum space itself and considered as contentious by General relativity. Quantization of space prove is one of the main goals of modern quantum gravity theory.
An effective method but not actual for representing the magnetic field strength using magnetic flux lines is instead of Tesla units to use Maxwell units thus number of lines per cm^2. For this units a 100μΤ field strength is represented with one line penetrating vertically a one cm^2 surface. This representation is symbolic however and not the actual physical number of lines that macroscopically and practically would appear to us as  "countless" nevertheless is a finite  number.
To get a feeling for example:
This calculator translates Tesla units to Maxwell (lines/cm^2). According, it says that 100μΤ correspond to one line per square cm thus  0.5 cm clearance from every side.
A quick calculation shows a $1T$ field has 10,000 lines/cm^2 which corresponds to a separation distance between the lines of 500 nm (i.e. there is a line present at regular 500nm intervals in space) for a homogeneous magnetic field assuming also the flux lines are infinite thin.
Again, this is just a representation of a given field strength using number of lines and the number of lines per field strength used by this unit cannot be taken literally. The discrete magnetic flux lines, streams of virtual photons consisting the field are physically there but in a finite number much much larger as represented by this unit.
