Attic fan installation
Yes, you can cut enough of the vertical 2x4 to install your vent fan.
Because 1) The 2x4 is “flat” against the gable end wall and is only used for nailing the sheathing (and presumably the siding) 2) there is no ridge beam, 3) spacing of the 2x4’s is 51” so the gable end wall is not structural.
If the “wall” seems a bit wobbly at the vent after you remove a portion over the vent opening, you could add horizontal stiffeners above and below the vent opening from adjacent 2x4’s.