Add a newline after every period

I need to add a newline after every period.

Here is some sample text.
The mechanisms for this type of conditioning are probably the same in humans. According to PET scans on young adults, when pairing a stimulus with an airpu produces a conditioned eye blink, activity increases in the cerebellum, red nucleus, and several other areas (Logan & Grafton, 1995). People who have damage in the cerebellum have weaker conditioned eye blinks, and the blinks are less accurately timed relative to the onset of the airpu (Gerwig et al., 2005).

Try this:

sed -e 's/\.  */.\n/g' -e 's/\.$/.\n/g' infile
tr '. ' '\n' < filename

That will convert every period and space to a newline, not append a newline after the period.

If that doesn't work for the OP, it's probably because \n in the replacement text is a GNU extension.

A more portable alternative:

sed 's/\. */.\
/g'

Regards,
Alister

1 Like

With awk

awk '{gsub(/\. /,".\n");print}' infile
1 Like