Reverse all words in current line
- by KasiyA
I have a file and I want to reverse all word in it. Read line as long as (.) not seen, or seen (\n), if found first (.) in line then It is a word , so reverse this word and continue reading for next word in current line until end of file.
ex input file:
DCBA. HGFE.GI
MLK,PON.RQ
UTS. ZYXWV. 321
ex output file: (What I Want)
ABCD. EFGH.IG
KLM,NOP.QR
STU. VWXYZ. 123
With this sed script: sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//' in the entire line is reversed.
The wrong output produced by the command above:
IG.EFGH .ABCD
QR.NOP,KLM
123 .VWXYZ .STU
How can I get my desired output? Thanks for your help