I am trying to remove the spaces from each line till the last word for each line in a file.
Example input file:
808 0 C01124 Amazon 45/234Birch 00 YYY 808 0 C01184 Flipkart 45/234Lotus 01 YYY 808 0 C01186 PrimeTime 45/23XCCCCH 08 YYY 808 0 C01125 DMART 5/23PPPPPPP 09 YYY
The format is somewhat like the above, with uneven spaces and the last word always being 'YYY'. My requirement is: there are spaces after the YYY that I want to preserve, but I want to remove all the other spaces.
8080C01124Amazon45/234Birch00YYY 8080C01184Flipkart45/234Lotus01YYY 8080C01186PrimeTime45/23XCCCCH08YYY 8080C01125DMART5/23PPPPPPP09YYY
I have tried using
tr commands, but it becomes a huge mess and all the lines become just one line. I want to segregate like above but I am not able to come to the requirement. How can I do it?