My goal is to add spaces in between letters of various abbreviations.
There are three conditions for abbreviations:
- abbreviations contain at least two or more letters.
- abbreviations are always capitalized.
- special character "/" is considered a capitalized letter
think of DNS, IP, TCP/IP, etc.
I would like to do text processing on them to turn into:
D N S
I P
T C P / I P
etc. Lets say I have this sentence
Because IP provides this basic routing function, the term “IP router,” is often used. Other, older terms for router are (IP gateway), [Internet gateway], and 'gateway'. TCP/IP 12345.
Running this command kinda solves my problem: sed -e "s/[a-z \, \. \' \“ \” \( \) 0-9]*/& /g" -e "s/ */ /g" test.txt
It doesn't get it quite perfectly.
I get this:
Because I P provides this basic routing function, the term “ I P router,” is often used. Other, older terms for router are ( I P gateway), [ Internet gateway ], and 'gateway'. T C P / I P 12345.
There is still a space between " and I P .
There is a space between ( and I P .
There is also a space between [ and Internet.
escaping [ and ] with $ sed -e "s/[a-z \, \. \' \“ \” \( \) \[ \] 0-9]*/& /g" -e "s/ */ /g" test.txt doesn't work as shown below.
Because IP provides this basic routing function, the term “IP router,” is often used. Other, older terms for router are (IP gateway), [Internet gateway], and 'gateway'. TCP/IP 12345.