Capt Stewart was commissioned by the Scottish regiment, the Cameronians, in 1915 at the age of 39 and was sent to France to command C Company after his training.
In one entry, the officer describes his irritation at having to put his pipe in his pocket during a gun battle because the smoke was drifting into his line of fire.
He wrote: "After my third or fourth shot, I found that the bowl of my pipe and the smoke from it was obscuring my line of vision as I was firing slightly downwards all the time.
"Just as I got my rifle working I saw a man in the trench calmly kneeling down and taking an aim at me.
"At the moment I saw him he fired. But in a miraculous way he missed."
Capt Stewart was sent home to Richmond, Surrey, after two years on the front line.
Describing the event with surprising humour, he wrote: "I started to cough and brought up some blood and a bit of the shell which must have stuck in my wind pipe.
"My servant very kindly retrieved the bit of iron out of the mud and handing it to me, remarked that I might like to keep it. This I did and my wife has it now."
Capt Stewart was due to return to the front line when the war ended a year later, and instead turned his attention to typing his memoir. However, he suffered from severe post-traumatic stress disorder following the war and spoke little of his experiences before his death from old age in 1964, at the age of 88.
His son, Thomas Stewart, 84, said: "He wanted to record what it was like, and he wrote well. For many years after the war he would wake up screaming in the night, but he never talked about it."
Jaime, an actor from Bristol, said: "I thought having something like that on a bookshelf was pointless.
"Until now it has only been read by one or two members of my family and close friends.
"But now, as his grandson, I'd like to share this amazing piece of personal history of his time in the trenches as an officer serving with the Scottish regiment The Cameronians."
Other extracts from Capt Alexander Stewart's war memoir include:
June 2, 1916: "The dugouts in this part of the line were infested with rats. They would frequently walk over one when asleep. I was much troubled by them coming and licking the brilliantine off my hair; for this reason, I had to give up using grease on my head. I never heard them biting anyone."
Nov 9, 1916: "I am very much annoyed by memos sent round from Headquarters that come in at all hours of the day and night; they stop me getting a full night's rest and some of them are very silly and quite unnecessary. When I am very tired and just getting off to sleep with cold feet, in comes an orderly with a chit asking how many pairs of socks my company had a week ago; I reply 141 and a half. "I then go to sleep; back comes a memo: 'please explain at once how you come to be deficient of one sock'. I reply 'man lost his leg'. That's how we make the Huns sit up."
Oct 29, 1917: "It was madness to attempt the attack. "It could only have been instigated by a higher command that had simply looked at a map, put down a finger and said: 'We will attack there'."
• The 260-page memoir, The Experiences of a Very Unimportant Officer, is available to download from www.grandfathersgreatwar.com, price £9.95.