-2

A sentence is a one that ends with period (.), exclamation(!) or question (?). I tried

tr '\n' ' ' <  input | sed -e 's/[.] \s*/. \\n/g'

I see \n added in my file but the line does not really break there.

I am using bash 3.2 version on Mac OS X Mavericks.

gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104
Shanthi
  • 39
  • 4

1 Answers1

0

See if this works. ( '\012' is new line character that tr command understands, you are replacing it with a blank space and then finally using sed to "capture" either a full stop/dot ., an exclamation !, or a question mark ? character using ( and ) and that whatever character will become available to \1 and after that you want \n new line for sed. sed boundary character that I used in the following example is #.

tr '\012' ' ' < someInputFile.txt | sed "s#\([\.\?\!]\)#\1\n#g"
AKS
  • 16,482
  • 43
  • 166
  • 258
  • This did not work me. I did finally figure out a solution - thanks to google. I had to put in a hard enter in the middle of a sed: sed 's/[.?!] /*\ /g' input.txt > sentences.txt – Shanthi Nov 15 '14 at 20:41
  • did you use ' or " in sed. – AKS Nov 17 '14 at 23:39