I would like to find an undetermined number of spaces and shorten them to one space. I am running Debian in mksh. Script running in #!/bin/sh. Sorry to not include all code. The program is too big and involves an online file... too much hassle to solve a simple issue.
Ex.,
I start with (pretend the periods are spaces),
"This . . . . sentence has . . . . . . an undetermined . . number of . spaces between . . . . . . each word."
The result would be:
"This sentence has an undetermined number of spaces."
What I have so far is working but extremely poor code:
This looks like a great program for one/two job operations, and I'll likely use it for other tasks now that I know it exists; but, I wanted to stick with awk and keep the programs to a minimum.
I don't want to use another pipe, and I cannot use this at the beginning of the code as it's a job that needs to wait til the end. Either way, the previous code works well enough.
If one doesn't want to use bakunin's suggestion because one is afraid the someone reading the code might not notice the literal <space> or literal <tab> in the ERE (and isn't willing to add a comment noting that the characters in that ERE are a literal <space> and <tab>), one could also use:
awk '{gsub (/[[:blank:]]+/, " ")}1' file
which does the same thing in most locales and is self-documenting. And, in locales where additional characters are members of the blank character class, you might also want this global substitution to produce replacements for them as well. If your code is likely to be used in locales like this, you should seriously consider whether you want to hard code these two characters or you want to use the character class definition.