Donald Trump has said journalists should be able to work without fear of facing violent attack – an comment that raised eyebrows among many in the industry given his frequent attacks against the so-called “fake news” media.

Addressing the mass shooting at the Capital Gazette newspaper in Annapolis, Maryland, that left five people dead, Mr Trump said: “This attack shocked the conscience of our nation and filled our hearts with grief.”

He had earlier been filmed walking silently past reporters requesting comment or words of condolences at the White House.

A gunman opened fire on the Maryland newsroom on Thursday afternoon. Police said the man had a grudge against the paper. The attack killed four journalists and a sales assistant.

“I’d like to address the horrific shooting that took place yesterday at Capital Gazette newsroom in Annapolis, Maryland,” Mr Trump said, speaking at a White House event marking the six-month anniversary of his $1.5 trillion tax cuts.

”Journalists, like all Americans, should be free from the fear of being violently attacked while doing their jobs. To the families of the victims there are no words to express our sorrow for your loss. Horrible, horrible event. Horrible thing happened.”

Maryland shooting: Capital Gazette newspaper staff targeted Show all 10 1 /10 Maryland shooting: Capital Gazette newspaper staff targeted Maryland shooting: Capital Gazette newspaper staff targeted Police respond to the shooting in Annapolis, AFP/Getty Images Maryland shooting: Capital Gazette newspaper staff targeted Pat Furgurson, staff reporter of the Capital Gazette, reports outside the scene of a shooting EPA/JAY FLEMING Maryland shooting: Capital Gazette newspaper staff targeted Police and first responders attend the scebe EPA Maryland shooting: Capital Gazette newspaper staff targeted A member of the FBI responds to the shooting in Annapoli AFP/Getty Images Maryland shooting: Capital Gazette newspaper staff targeted Authorities work at the scene AP Maryland shooting: Capital Gazette newspaper staff targeted Emergency personnel outside the Capital-Gazette newspaper Getty Images Maryland shooting: Capital Gazette newspaper staff targeted Capital Gazette reporter Chase Cook, right, and photographer Joshua McKerrow, left, work on the next days newspaper while awaiting news from their colleagues. AFP/Getty Images Maryland shooting: Capital Gazette newspaper staff targeted Police respond to a shooting in Annapolis, Maryland, June 28, 2018. At least five people were killed Thursday when a gunman opened fire inside the offices of the Capital Gazette, a newspaper published in Annapolis, a historic city an hour east of Washington.A reporter for the daily, Phil Davis, tweeted that a "gunman shot through the glass door to the office and opened fire on multiple employees.""There is nothing more terrifying than hearing multiple people get shot while you're under your desk and then hear the gunman reload," Davis said. / AFP PHOTO / SAUL LOEBSAUL LOEB/AFP/Getty Images SAUL LOEB AFP/Getty Images Maryland shooting: Capital Gazette newspaper staff targeted "This was a targeted attack on the Capital Gazette," William Krampf, the Anne Arundel County acting police chief, said Thursday evening during a press conference, referring ot the joint name that appears at the office to describe the two papers that work inside. "This person was prepared today to come in. This person was prepared to shoot people. His intent was to cause harm, and as I've stated before, the investigative part of this is going to be thorough, and it's going to take some time," EPA Maryland shooting: Capital Gazette newspaper staff targeted Police secure the scene AP

“When you’re suffering, we pledge our eternal support, the suffering is so great, I’ve seen some of the people, so great,” the president added. “My government will not rest until we have done everything in our power to reduce violent crime and to protect innocent life,” Mr Trump said. “So our warmest best wishes and regrets. A horrific and horrible thing.”

Jarrod Ramos has been charged with five counts of murder. He appeared in court on Friday morning where he was refused bail. He has not yet had an opportunity to enter a plea.

The 38-year-old lost a defamation lawsuit against the paper in 2012 after it reported his harassment of a woman he went to school with.

Warm relations with the media has not been Mr Trump’s strong point throughout his presidency. He has repeatedly referred to the media as the “enemy of the people,” and the catchphrase “fake news” has become something of a Trump-ist slogan to dismiss any and all criticism of Trump and his administration in the press.

Mr Trump has also avoided sitting down for one-on-one interviews with reporters, with the exception of a few appearances on the largely sympathetic Fox News.