I have a text file that consists of some N ORMAL E NGLISH W ORDS in all-caps. Unfortunately, these words all have a space between the first and following letters, which is not acceptable. I tried writing a sed expression that would match these occurrences sed 's/[A-Z] [A-Z][A-Z]*/, and I was successful. However, I was not successful in writing the replacement part.
|
|
|||
|
|
You would need to group the two parts of the word and use them as backreferences in the replacement like this:
Note that I also changed your use of Also you might have problems with this whole expression if the word 'I' is found by itself. Do you have anything else you can match on to know whether an I should be it's own word or joined to the next? What about 'A' and other single letter words? I recommend combining this simple text hack with some kind of spell-check so that to help check for mistakes made by the replace such as "ABIRD" or "IWENT". No amount of regex fiddling is going to give you a perfect result on a large corpus of broken text like you describe, but once you've done some rough cleanup with regex you can go on to finer-tuned methods like spell checkers (which can also be run from the command line and automated) to clean things up. Finally, have a human proof-read it! |
||||
|
|