For UA, they use a hand luggage checker at the gate, which is sized very slightly larger than the official dimensions. If it fits in that, you are fine.
However UA's passengers take on board far far more hand baggage than you will be used to seeing at EDI. The flight to EWR should be fine but, on the domestic flight, it's likely that they will have run out of space on the plane by the time your boarding group is called so you might have to gate check your bag. This will be free but be prepared to grab what you need for the flight.