Add white space

hi guys

how can i add spacein file name with sed if strings have no space around dash

input

19-20  
( 18-19 )
ABC-EFG

output after add white space

19 - 20 
(18 - 19 )
ABC  - EFG

thx in advance

$ sed -e 's/\([^ ]\)-/\1 -/g' -e 's/-\([^ ]\)/- \1/' infile > outfile
1 Like
awk '{gsub(/ /,x);gsub(/-/," - ")}1' file
19 - 20
(18 - 19)
ABC - EFG