How do I use tr command to replace: full stops, exclamations and question marks followed by a space, with newlines?
You don't. tr
is not designed for that. It's designed to transliterate a set of single characters into another set of single characters, e.g., A-Z
into a-z
. Using tr
with .␣
(a dot and a space) and \n
will replace all dots and spaces with newlines.
Use (GNU) sed
instead:
$ echo 'I am happy. I am here. How are you, Meg?' | sed 's/\([!.?]\) /\1\n/g'
I am happy.
I am here.
How are you, Meg?
The sed
editing script here will replace all occurrences of !
, .
or ?
that are followed by a space, by the same character and a newline.
As far as I know tr
only works with single characters and ". " is a string not a character, so it is possible to do what you want by using sed
or awk
, for example:
sed -e "s/\. /\n/g" file.txt > out.txt