Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 2
    The POSIX equivalent would be tr -s ' \t' '[\n*]'. See also tr -s '[:space:]' '[\n*]' or tr -s '[:blank:]' '[\n*]' Commented Nov 14, 2017 at 18:45
  • This fails on "AC/DC", "add-on", "AT&T". You need something like tr -s ' \t,."' '\n' <file Commented Apr 20, 2021 at 22:56
  • @Isaac Well, that’s debatable. The question says, “Assume that words may contain (non-blank) non-alphabetic characters”. (Disclosure: I edited the question to say that, with the intent of keeping my answer correct.) If words may contain non-alphabetic characters, then "AC/DC", "add-on" and  "AT&T" are all words. And the OP didn’t give us any clue how they want “Mr.”, “Mrs.”, “Ph.D” or “Q.E.D.” to be handled. While comma (and semicolon) maybe should always be separators, people with 20th century technology sometimes used " to denote umlaut / dieresis; e.g., na"ive for naïve. Commented Apr 20, 2021 at 23:48
  • Fair enough. @G-ManSays'ReinstateMonica' Commented Apr 20, 2021 at 23:56
  • That would output a blank line at the start of the OPs 2nd set of input (the one that starts with spaces). Commented Dec 24, 2021 at 8:26