How to modify sentence in following format : I have a input string "SQLSELECT SELECT location_id, department_name "Department" FROM tttt UNION SQLSELECT SELECT location_id, warehouse_name FROM warehouses EXCEPT  SQLSELECT SELECT location_id, department_name "Department" FROM XYZ UNION ALL  SQLSELECT SELECT location_id, warehouse_name FROM PQR INTERSECT  SQLSELECT SELECT location_id, warehouse_name FROM ABC".

and I want output string in this format  "UNION 
SQLSELECT SELECT location_id, department_name "Department" FROM tttt  
EXCEPT 
SQLSELECT SELECT location_id, warehouse_name FROM warehouses  
UNION ALL 
SQLSELECT SELECT location_id, department_name "Department" FROM XYZ   
INTERSECT 
SQLSELECT SELECT location_id, warehouse_name FROM PQR   
SQLSELECT SELECT location_id, warehouse_name FROM ABC" 